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];
    }

你可能感兴趣的:(iOS 版本更新)