#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[];
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==)
{
//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

最新文章

  1. Bucket不为空,请检查该Bucket是否包含未删除的Object或者未成功的Multipart碎片
  2. ex3-数字和数字计算
  3. (转)[BetterExplained]为什么你应该(从现在开始就)写博客
  4. 初学git:用git bash往github push代码
  5. October 12th 2016 Week 42nd Wednesday
  6. Hash索引和BTree索引区别
  7. C#解leetcode 189. Rotate Array
  8. 几个常用道的macro
  9. eval全局作用域和局部作用域的坑!
  10. java中构造方法及其作用
  11. Could not find property &#39;outputFile
  12. Linux上文件恢复工具
  13. lvs用户空间命令ipvsadm
  14. 通过TCPView工具查看foxmail用exchange方式连接exchange时用什么端口
  15. spring4笔记----spring4构造注入
  16. BZOJ.3170.[TJOI2013]松鼠聚会(切比雪夫距离转曼哈顿距离)
  17. android中通过intent传递复杂数据
  18. Spring 中PageHelper分页插件使用
  19. 运行mysql时,提示Table ‘performance_schema.session_variables’ doesn’t exist
  20. 796B Find The Bone

热门文章

  1. springboot+layui实现增删查改
  2. python3 package management 包管理 实例
  3. 《HTML与CSS知识》系列分享专栏
  4. meta标签的总结
  5. 对于微信小程序登录的理解图
  6. 成都Uber优步司机奖励政策(4月8日)
  7. 长沙Uber司机奖励政策(8月24日到8月30日)
  8. 【POJ1733】Parity game
  9. LeetCode:33. Search in Rotated Sorted Array(Medium)
  10. spring-boot、spring-data-jpa、hibernate整合