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

2016-04-09  本文已影响0人  zbj_

//拼接查询参数进行查询
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];

上一篇 下一篇

猜你喜欢

热点阅读