[置顶] 检查版本更新
2016-06-03 15:49
246 查看
1、
// FIR.im的自动更新
2、
// FIR.im的自动更新
NSString *bundleId = [[NSBundlemainBundle]infoDictionary][@"CFBundleIdentifier"]; NSString *bundleIdUrlString = [NSStringstringWithFormat:@"http://api.fir.im/apps/latest/%@?api_token=71eb982be4f093719d2b7d985b236fb7&type=ios", bundleId]; NSURL *requestURL = [NSURLURLWithString:bundleIdUrlString]; NSURLRequest *request = [NSURLRequestrequestWithURL:requestURL]; [NSURLConnectionsendAsynchronousRequest:requestqueue :[NSOperationQueuecurrentQueue]completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) { if (connectionError) { //do something XNLog(@"版本检查失败"); }else { NSError *jsonError =nil; id object = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:&jsonError]; if (!jsonError && [objectisKindOfClass:[NSDictionaryclass]]) { //do something //NSString * version=object[@"version"]; //对应 CFBundleVersion,对应Xcode项目配置"General"中的 Build NSString * versionShort=object[@"versionShort"];//对应 CFBundleShortVersionString,对应Xcode项目配置"General"中的 Version //NSString * localVersion=[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"]; NSString * localVersionShort=[[NSBundlemainBundle]infoDictionary][@"CFBundleShortVersionString"]; nss_updateURL=object[@"update_url"];//如果有更新需要用Safari打开的地址 //NSString *changelog=object[@"changelog"]; //如果有更新需要用Safari打开的地址 if (![localVersionShort isEqualToString:versionShort]) { [[AlertHandlersingleton]showConfirm_default_title:@"发现新版本"message:[NSStringstringWithFormat:@"发现新版本v%@",versionShort]delegate:self cancelButtonTitle:@"忽略"otherButtonTitle:@"点击更新"tag:1]; } } } }];
2、
<span style="font-size:18px;">if ([[CommFunsingleton]event_updateVersion] ==YES) { UIApplication *application = [UIApplicationsharedApplication]; [applicationopenURL:[NSURLURLWithString:[UesrInfosingleton].updateURL]]; }else{ NSString * localVersionShort=[[NSBundlemainBundle]infoDictionary][@"CFBundleShortVersionString"]; [[AlertHandlersingleton]showConfirm_default_title:[NSStringstringWithFormat:@"当前版本v%@", localVersionShort]message:@"当前已是最新版本"delegate:selfcancelButtonTitle:@"确定"otherButtonTitle:niltag:1]; } -(BOOL)event_updateVersion{ // TODO:去掉版本检查(苹果审核不通过) [UesrInfosingleton].needUpdate =NO; returnNO; [UesrInfosingleton].needUpdate =YES; NSString *bundleId = [[NSBundlemainBundle]infoDictionary][@"CFBundleIdentifier"]; NSString *bundleIdUrlString = [NSStringstringWithFormat:@"http://api.fir.im/apps/latest/%@?api_token=71eb982be4f093719d2b7d985b236fb7&type=ios", bundleId]; NSURL *requestURL = [NSURLURLWithString:bundleIdUrlString]; NSURLRequest *request = [NSURLRequestrequestWithURL:requestURL]; [NSURLConnectionsendAsynchronousRequest:requestqueue :[NSOperationQueuecurrentQueue]completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) { if (connectionError) { //do something XNLog(@"版本检查失败"); }else { NSError *jsonError =nil; id object = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:&jsonError]; if (!jsonError && [objectisKindOfClass:[NSDictionaryclass]]) { //do something //NSString * version=object[@"version"]; //对应 CFBundleVersion,对应Xcode项目配置"General"中的 Build NSString * versionShort=object[@"versionShort"];//对应 CFBundleShortVersionString,对应Xcode项目配置"General"中的 Version //NSString * localVersion=[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"]; NSString * localVersionShort=[[NSBundlemainBundle]infoDictionary][@"CFBundleShortVersionString"]; NSString *nss_updateURL=object[@"update_url"];//如果有更新需要用Safari打开的地址 //NSString *changelog=object[@"changelog"]; //如果有更新需要用Safari打开的地址 if (![localVersionShort isEqualToString:versionShort]){ [UesrInfosingleton].needUpdate =YES; }else{ [UesrInfosingleton].needUpdate =NO; } [[UesrInfosingleton]setUpdateURL:nss_updateURL]; } } }]; return [UesrInfosingleton].needUpdate; } -(void)setUpdateURL:(NSString *)updateURL{ NSMutableDictionary *updateURLDic = [[NSMutableDictionaryalloc]initWithObjectsAndKeys:updateURL,@"updateURL",nil]; [PlistReaderdoWrite:@"updateURL"dic:updateURLDic]; }</span>
相关文章推荐
- SpringMvc入门三----控制器
- 面向对象特性分析
- codeforces-3A-Shortest path of the king( 棋盘最短路径 + 贪心 )
- GCD学习之dispatch_suspend/dispatch_resume
- Binary Tree Zigzag Level Order Traversal
- C++项目中的extern "C" {}
- mybatis学习1
- url——input的新类型
- GCD浅析
- 培训讲解——创建第一个工程
- 路由器刷openwrt
- Java垃圾回收工作原理
- 邻接表vector HDU 3478 catch
- 深入理解Javascript中的自执行匿名函数
- spring aop
- 无法绑定到目标方法,因其签名或安全透明度与委托类型的签名或安全透明度不兼容。
- 浅谈JavaScript前端开发的MVC结构与MVVM结构
- Android仿外卖购物车
- 【Linux】super daemon的配置文件
- Entity Framework Code First (七)空间数据类型 Spatial Data Types