iOS版本升级提醒

作者: 遛遛食 | 来源:发表于2017-07-04 17:22 被阅读204次

关于iOS版本升级,苹果是不允许用户有强制用户升级的提示的,但是为了让用户知道APP更新了,一般APP里面是会有版本升级提示。下面来介绍一下一般都是怎么做的。

方法一:

可以访问itunes拿到iTunes里面的APP版本号,然后与本地的APP版本号进行对比,就可以判断出是否需要升级了
优点:不需要对自己的服务器进行任何操作
缺点:访问itunes会比较慢,所以请求响应时间会比较长
请求网址:

https://itunes.apple.com/lookup?id=APPID

这个会返回你的APP在App Store的所有信息

//这个就是请求后拿到的App Store的版本号
NSString *appStoreVersion = [responseObject[@"results"] lastObject][@"version"];
//获取当前的APP的版本号
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

把两个版本号进行判断,注意不能直接转化为double类型

[appStoreVersion compare:appVersion options:NSNumericSearch] == NSOrderedDescending

if ([appStoreVersion compare:appVersion options:NSNumericSearch] == NSOrderedDescending) {//需要升级
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请升级版本" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSString *str = @"itms-apps://itunes.apple.com/app/id1228061385";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:sure];
    [alertVC addAction:cancel];
    [self presentViewController:alertVC animated:YES completion:nil];
}else{//不需要升级
    NSLog(@"不要升级");
}

方法二:

往自己的服务器上发一个请求,获取最新的版本号与本地的APP版本号进行判断
优点:因为访问的是自己的服务器,所以响应快
缺点:需要自己的服务器去做对应的接口和数据

相关文章

网友评论

本文标题:iOS版本升级提醒

本文链接:https://www.haomeiwen.com/subject/mrsxhxtx.html