美文网首页
iOS 怎么在app里提示版本更新

iOS 怎么在app里提示版本更新

作者: 李炯7115 | 来源:发表于2017-07-12 17:57 被阅读60次

#import "ViewController.h"

@interfaceViewController ()

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

self.title=@"版本检测更新";

self.view.backgroundColor= [UIColorwhiteColor];

[selfcheckVersion];//检测升级

}

-(void)checkVersion

{

NSString*newVersion;

NSURL*url = [NSURLURLWithString:@"http://itunes.apple.com/cn/lookup?id=1139094792"];//这个URL地址是该app在iTunes connect里面的相关配置信息。其中id是该app在app store唯一的ID编号。

NSString*jsonResponseString = [NSStringstringWithContentsOfURL:urlencoding:NSUTF8StringEncodingerror:nil];

NSLog(@"通过appStore获取的数据信息:%@",jsonResponseString);

NSData*data = [jsonResponseStringdataUsingEncoding:NSUTF8StringEncoding];

//    解析json数据

idjson = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableContainerserror:nil];

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

for(NSDictionary*dic in array) {

newVersion = [dicvalueForKey:@"version"];

}

NSLog(@"通过appStore获取的版本号是:%@",newVersion);

//获取本地软件的版本号

NSString*localVersion = [[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleVersion"];

NSString*msg = [NSStringstringWithFormat:@"你当前的版本是V%@,发现新版本V%@,是否下载新版本?",localVersion,newVersion];

//对比发现的新版本和本地的版本

if([newVersionfloatValue] > [localVersionfloatValue])

{

UIAlertController*alert = [UIAlertControlleralertControllerWithTitle:@"升级提示"message:msgpreferredStyle:UIAlertControllerStyleAlert];

[selfpresentViewController:alertanimated:YEScompletion:nil];

[alertaddAction:[UIAlertActionactionWithTitle:@"现在升级"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction* _Nonnull action) {

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"https://itunes.apple.com/cn/app/yi-ka-tongbic-ban/id1139094792?l=en&mt=8"]];这里写的URL地址是该app在app store里面的下载链接地址,其中ID是该app在app store对应的唯一的ID编号。

NSLog(@"点击现在升级按钮");

}]];

[alertaddAction:[UIAlertActionactionWithTitle:@"下次再说"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction* _Nonnull action) {

NSLog(@"点击下次再说按钮");

}]];

}

}

相关文章

网友评论

      本文标题:iOS 怎么在app里提示版本更新

      本文链接:https://www.haomeiwen.com/subject/mtabhxtx.html