小知识点-ios跳过app store更新版本
2024-10-11 21:08:16
版本更新实现的思路
- 获取自身的版本号
- 获取AppStore的版本号
- 自身的版本号和AppStore的比较
- 弹窗提示所需数据的获取的方式
- 1.获取自身的版本号
2.AppStore的版本号
WechatIMG58.jpeg具体实现的代码
网络请求app的信息
-(void)VersonUpdate{
//定义的app的地址
NSString *urld = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"你的APPID"]; //网络请求app的信息,主要是取得我说需要的Version
NSURL *url = [NSURL URLWithString:urld];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10];
[request setHTTPMethod:@"POST"]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSMutableDictionary *receiveStatusDic=[[NSMutableDictionary alloc]init];
if (data) { //data是有关于App所有的信息
NSDictionary *receiveDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
if ([[receiveDic valueForKey:@"resultCount"] intValue]>0) { [receiveStatusDic setValue:@"1" forKey:@"status"];
[receiveStatusDic setValue:[[[receiveDic valueForKey:@"results"] objectAtIndex:0] valueForKey:@"version"] forKey:@"version"]; //请求的有数据,进行版本比较
[self performSelectorOnMainThread:@selector(receiveData:) withObject:receiveStatusDic waitUntilDone:NO];
}else{ [receiveStatusDic setValue:@"-1" forKey:@"status"];
}
}else{
[receiveStatusDic setValue:@"-1" forKey:@"status"];
}
}]; [task resume];
}- 获取自身的版本号并与AppStore比较
-(void)receiveData:(id)sender
{
//获取APP自身版本号
NSString *localVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"]; NSArray *localArray = [localVersion componentsSeparatedByString:@"."];
NSArray *versionArray = [sender[@"version"] componentsSeparatedByString:@"."]; if ((versionArray.count == 3) && (localArray.count == versionArray.count)) { if ([localArray[0] intValue] < [versionArray[0] intValue]) {
[self updateVersion];
}else if ([localArray[0] intValue] == [versionArray[0] intValue]){
if ([localArray[1] intValue] < [versionArray[1] intValue]) {
[self updateVersion];
}else if ([localArray[1] intValue] == [versionArray[1] intValue]){
if ([localArray[2] intValue] < [versionArray[2] intValue]) {
[self updateVersion];
}
}
}
}
}- 根据比较的结果,实现弹窗
-(void)updateVersion{
NSString *msg = [NSString stringWithFormat:@"更新最新版本,优惠信息提前知"];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"升级提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"现在升级"style:UIAlertActionStyleDestructive handler:^(UIAlertAction*action) { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"你的app在商店的下载地址"]];
[[UIApplication sharedApplication]openURL:url];
}];
[alertController addAction:otherAction];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil]; }温馨提示
- 我这种实现的方式是根据自身的版本和线上版本,比较大小来实现的弹窗,如果比线上的版本小,就会弹窗,具体的比较看上面的代码。这样上线可以瞒天过海。
- 当你想实现提醒更新的时候,直接的把我上面的代码,copy到AppDelegate里面即可,当然还要换上你自己的appid,具体的获取方式,上面已经写明。
- 如果想模拟器测试效果,只要把version改的比线上的版本小就可以。
- 我的弹窗比较“简陋”,具体的好看的效果,还需要自己去改变了。
最新文章
- Array(数组)--map方法
- nginx 自动忽略request中header name包含下划线参数的解决方法
- Java基础知识学习(七)
- html5用到的js
- Dynamics AX 2012 R2 AIF 错误 &#39;/MicrosoftDynamicsAXAif60&#39; 应用程序中的服务器错误
- Yii 1 数据库操作 笔记
- Linux递归删除文件命令
- 【BZOJ 3122】 [Sdoi2013]随机数生成器 (BSGS)
- Delphi 进阶基础技能说明
- 一个Jquery特效(转)
- mysql 发生系统错误1067的解决方法
- php发送get、post请求获取内容的几种方法
- (转)Hadoop的InputFormats和OutputFormats
- java程序设计习题总结
- Hadoop生产环境配置文件
- git 查看提交的信息diff
- vue / js使用video获取视频时长
- Mac OS下Android Studio的Java not found问题,androidfound
- 查看用户信息:w
- NodeList、HTMLCollection和NamedNodeMap