检测AppStore软件更新
2016-07-22 16:40
489 查看
1、拿到自己的app版本 2、获取AppStore上的版本 3、对比AppStore版本和现在app版本如果大于就提示更新 #import "ViewController.h" //1一定要先配置自己项目在商店的APPID,配置完最好在真机上运行才能看到完全效果哦 #define STOREAPPID @"1080182980" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //一句代码实现检测更新 [self hsUpdateApp]; } /** * 天朝专用检测app更新 */ -(void)hsUpdateApp { //2先获取当前工程项目版本号 NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary]; NSString *currentVersion=infoDic[@"CFBundleShortVersionString"]; //3从网络获取appStore版本号 NSError *error; NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID]]] returningResponse:nil error:nil]; if (response == nil) { NSLog(@"你没有连接网络哦"); return; } NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; if (error) { NSLog(@"hsUpdateAppError:%@",error); return; } NSArray *array = appInfoDic[@"results"]; NSDictionary *dic = array[0]; NSString *appStoreVersion = dic[@"version"]; //打印版本号 NSLog(@"当前版本号:%@\n商店版本号:%@",currentVersion,appStoreVersion); //4当前版本号小于商店版本号,就更新 if([currentVersion floatValue] < [appStoreVersion floatValue]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"检测到新版本(%@),是否更新?",appStoreVersion] delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil]; [alert show]; }else{ NSLog(@"版本号好像比商店大噢!检测到不需要更新"); } } - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { //5实现跳转到应用商店进行更新 if(buttonIndex==1) { //6此处加入应用在app store的地址,方便用户去更新,一种实现方式如下: NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", STOREAPPID]]; [[UIApplication sharedApplication] openURL:url]; } } @end
相关文章推荐
- 个人信息安全报告发布:有 APP 每分钟调用位置权限 1468 次
- 下载量超过一亿的流行应用被发现含有恶意模块
- 苹果与Siri的七年之痒:“宫斗”戏码不断上演
- APP添加CNZZ统计插件教程 Android版添加phonegap
- ExtJS Store的数据访问与更新问题
- 深入浅析Extjs中store分组功能的使用方法
- Android APP与媒体存储服务的交互
- java实现收藏名言语句台词的app
- SQLSERVER Pager store procedure分页存储过程
- 修改Android App样式风格的方法
- Android App数据格式Json解析方法和常见问题
- 微信APP支付Java代码
- 通过Html网页调用本地安卓(android)app程序代码
- 百度地图API提示230 错误app scode码校验失败的解决办法
- js判断移动端是否安装某款app的多种方法
- PHP实现批量生成App各种尺寸Logo
- Could not load file or assembly "App_Licenses.dll"的问题
- Android桌面组件App Widget用法入门教程
- Android天气预报app改进版