iOS 版本更新

  1. 获取本机版本号

NSDictionary *localDic = [[NSBundle mainBundle] infoDictionary];
NSString *localVersions = [localDic objectForKey:@"CFBundleShortVersionString"];

  1. 查看appstore中的软件最新版本

地址:https://itunes.apple.com/lookup?id=软件的apple Id

NSArray *resultArr = responseObject[@"results"];
NSDictionary *resultDic = resultArr.firstObject;
NSString *latestVersion = resultDic[@"version"];

  1. 如果版本不一致,进行更新

if ([latestVersion compare:localVersions options:NSNumericSearch] == NSOrderedDescending) {
[self updateBtnActionwithLatestVersion:latestVersion];
}

  • (void)updateBtnActionwithLatestVersion:(NSString *)latestVersion {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"检查到最新版本" message:latestVersion preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];
    UIAlertAction *updateAction = [UIAlertAction actionWithTitle:@"下载" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    UIApplication *application = [UIApplication sharedApplication];
    [application openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/id软件的Apple id"]];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:updateAction];
    [self presentViewController:alertController animated:YES completion:nil];
    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容