您的位置:首页 > 移动开发

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: