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

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容