IOS 根据 AppStore 版本号检测当前版本和升级

// 获取当前项目版本号    

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];    

NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];    

// 获取AppStore 版本号    

NSURLSession * session = [NSURLSession sharedSession];    

NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@",APP_ID]]];    

NSURLSessionTask * sessionTask = [session dataTaskWithRequest:request                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {                        

                            if (data == nil) return;   

                            NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];        

                            if (error) return;               

                            NSArray *array = appInfoDic[@"results"];        

                            if (array.count<1) return;

                            NSDictionary *dic = array[0];        

                            // 商店版本号        

                            NSString *appStoreVersion = dic[@"version"];       

                             // 回到主线程更新UI        

                            dispatch_async(dispatch_get_main_queue(), ^{           

                                if ([appStoreVersion compare:app_Version options:NSNumericSearch] ==NSOrderedDescending) {                

                                    // 版本有更新,弹出提示框

                                } 

                            });                                                

}];   

[sessionTask resume];


tips:

1、如果应用还未发布,可以登陆开发者账号到 App Store Connect 上查看 App ID。

2、如果上架的时候只选中国地区,请求路径使用"https://itunes.apple.com/cn/lookup?id="。

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

推荐阅读更多精彩内容