app升级,获取AppStore版本号和本地版本号
2015-10-20 15:07
369 查看
1.获取远程版本号
代码:比如随便新建一个demo- (void)viewDidLoad { [super viewDidLoad]; // 获取appStore版本号 最后一串数字就是当前app在AppStore上面的唯一id NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"414478124"]; [self Postpath:url]; } #pragma mark -- 获取数据 -(void)Postpath:(NSString *)path { NSURL *url = [NSURL URLWithString:path]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; [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]>0) { [receiveStatusDic setValue:@"1" forKey:@"status"]; [receiveStatusDic setValue:[[[receiveDic valueForKey:@"results"] objectAtIndex:0] 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); }
说明:上面代码中的这行代码后面那串数字,就是app在AppStore上面的唯一id
NSString *url = [[NSStringalloc]initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"704253962"];
比如随便在AppStore上面打开一个APP,复制其链接(只要链接中的数字)
https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8
结果:
2.获取本地版本号
NSString* thisVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString*)kCFBundleVersionKey];
3.跳转到AppStore下载
//APPid就是上面的那串数字NSString *urlStr = [NSStringstringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",APPID];
NSURL *url = [NSURLURLWithString:urlStr];
[[UIApplicationsharedApplication]openURL:url];
相关文章推荐
- NSURLConnection的几种请求方式
- Android Activity回穿值总结
- IOS 字体大全
- Android 监听scrollview滚动实现ToolBar显示和隐藏的效果
- Cocos2d提供的字体!共57种(有对照的字体图)
- 如何解决android模拟器慢的问题
- Android基础:shape的基本用法
- Android应用(测试/正式)服务器端接口切换方法
- 如何基于OpenShift进行微信公众号开发
- iOS使用系统API扫描二维码条形码&限制扫描区域
- iOS: SegmentControl 实现页面切换的四种方法
- Android Drawable 那些不为人知的高效用法
- Android 相对布局中的 代码中修改属性与布局文件的设置不同的解决方法
- 如何向android studio 中添加第三方软件包
- android 不错的博客(国内,国外)
- android限制app的敏感ContentProvider的可访问性
- Android自定义控件之自定义Toast
- iOS使用zbar以及AVFoundation实现二维码扫描
- ActiveAndroid 管理数据库
- Android APP: BlackContact 添加/更新/删除名单信息