iOS从app store获取版本进行更新

//拼接查询参数进行查询
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&entity=software&sort=recent&limit=1", @"喜马拉雅FM"];

//将中文进行转码 NSString *encodeUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

//发送Get请求
[HttpEngineTool HttpGETRequest:encodeUrl success:^(id responseDic) { self.versionArr = responseDic[@"results"];
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *serverVersion = self.versionArr[0][@"version"];
//trackViewUrl为当前app的信息页
NSString *openUrl = self.versionArr[0][@"trackViewUrl"];
if ([version floatValue] < [serverVersion floatValue]) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"有新版本升级" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]]; }];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }];
[alert addAction:ok];
[alert addAction:cancel];
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];

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

推荐阅读更多精彩内容