iOS APP 版本更新檢測

URL地址: https://itunes.apple.com/cn/lookup?id=你的AppId
參數AppId指的是你在APP在創建后的唯一標識,在iTunes Connect里可以查找到此信息。

tmp58d9db39.png

獲取線上版本信息(字段---version)

//獲取當前bundle中的版本號
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

//獲取App Store中當前APP的版本號
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
    NSArray *array = responseObject[@"results"];
    NSDictionary *dict = [array lastObject];
    NSLog(@"線上版本:%@", dict[@"version"]);
    
    NSString *lineVersion = dict[@"version"];
    
    if ([lineVersion compare:currentVersion options:NSNumericSearch] == NSOrderedDescending)
    {
        //appstore 版本更高
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message: [NSString stringWithFormat:@" 新版本 %@ 已發布 ! ", lineVersion] delegate:self cancelButtonTitle:@"以后再說" otherButtonTitles: @"馬上更新", nil];
        [alert show];

        NSLog(@"線上版本:%@ 更高", lineVersion);
    }
    else
    {
        NSLog(@"當前版本:%@ 更高", currentVersion);
    }
   //返回json中的trackViewUrl就是App Store中當前APP的下載頁面
      self.trackViewUrl = dict[@"trackViewUrl"];
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
         NSLog(@"錯誤  : %@",error);
}];

//跳轉App Store頁面進行下載
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:self.trackViewUrl]];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容