检查新版本 更新  第一种方法

  //检查新版本 更新

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ), ^{
// 耗时的操作 //获取本地版本号
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *build = [infoDictionary objectForKey:@"CFBundleVersion"];
NSString *nowVersion = [NSString stringWithFormat:@"%@.%@", version, build]; //获取appStore网络版本号
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", @""]];
NSString * file = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; NSRange substr = [file rangeOfString:@"\"version\":\""];
NSRange range1 = NSMakeRange(substr.location+substr.length,);
// NSRange substr2 =[file rangeOfString:@"\"" options:nil range:range1];
NSRange substr2 = [file rangeOfString:@"\"" options:NSCaseInsensitiveSearch range:range1];
NSRange range2 = NSMakeRange(substr.location+substr.length, substr2.location-substr.location-substr.length);
NSString *appStoreVersion =[file substringWithRange:range2]; dispatch_async(dispatch_get_main_queue(), ^{
// 更新界面 //如果不一样去更新
if(![nowVersion isEqualToString:appStoreVersion])
{ [self showAlert]; } });
}); /**
* 检查新版本更新
*/
-(void)showAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"有新的版本啦~~" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前去更新",nil];
[alert show]; } - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==)
{
// 此处加入应用在app store的地址,方便用户去更新,一种实现方式如下:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", @""]];
[[UIApplication sharedApplication] openURL:url];
}
}

检查新版本 更新  第二种方法

// 获取appStore版本号
NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@""]; [self Postpath:url]; #pragma mark -- 获取数据
-(void)Postpath:(NSString *)path
{ NSURL *url = [NSURL URLWithString:path];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:]; [request setHTTPMethod:@"POST"]; NSOperationQueue *queue = [NSOperationQueue new]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){
NSMutableDictionary *receiveStatusDic=[[NSMutableDictionary alloc]init];
if (data) { NSDictionary *receiveDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
if ([[receiveDic valueForKey:@"resultCount"] intValue]>) { [receiveStatusDic setValue:@"" forKey:@"status"];
[receiveStatusDic setValue:[[[receiveDic valueForKey:@"results"] objectAtIndex:] valueForKey:@"version"] forKey:@"version"];
}else{ [receiveStatusDic setValue:@"-1" forKey:@"status"];
}
}else{
[receiveStatusDic setValue:@"-1" forKey:@"status"];
} [self performSelectorOnMainThread:@selector(receiveData:) withObject:receiveStatusDic waitUntilDone:NO];
}]; } -(void)receiveData:(id)sender
{
NSLog(@"receiveData=%@",sender); } 最后打印出来的字典中就包含 版本号 receiveData={
status = ;
version = "1.0.0";
}

最新文章

  1. AC自动机+全概率+记忆化DP UVA 11468 Substring
  2. Linq实现DataTable的分组统计
  3. mesos资源动态分配测试
  4. 任意阶魔方阵(幻方)的算法及C语言实现
  5. httplib
  6. Dynamic Programming - Part1
  7. js 发红包
  8. 如何调试msbuild?
  9. chromedriver release note
  10. Oracle_表数据拆分与合并
  11. oracle 10g函数大全--分析函数
  12. Js 30 BOM
  13. opengl微发展理解
  14. Android自定义View的套路
  15. python tesserocr ImportError: dll loading failed 一个不常遇见的错误,以及简单的python安装方法~
  16. element-ui <el-input> 注册blur事件
  17. Hive 数据的导入导出
  18. 第15课 右值引用(2)_std::move和移动语义
  19. spring cloud 学习(5) - config server
  20. GO学习笔记 - 数据类型转换

热门文章

  1. 编写简单的ramdisk(无请求队列)
  2. mac使用终端运行mysql,mysql终端,mysql mac,mysql目录,mysql路径
  3. Spring 4 + Reactor Integration Example--转
  4. js ES6 对字符的操作注意事项
  5. selenium操作隐藏的元素
  6. 原创:跳坑指南——微信小程序真机预览跟本地不同的问题
  7. 【Android】《App研发录》总结
  8. MVC利用MvcHtmlString在后台生成HTML
  9. [Q&A] 远程过程调用失败。[0x800706be]
  10. Asp.net 面向接口可扩展框架之类型转化基础服务