项目上线以后一般都涉及到升级,那么iOS 如何从appstore获取到版本号
其实很简单
NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"987953868"];
其中 最后一串数字就是当前app的唯一id。 这个id如何得到,百度一下 很简单
然后我们只需要调用这个 地址,就会返回当前app的一些信息,其中就包括appstore上的版本号(前提是项目已经上线到appstore)
我们把获取的过程做了整理 大家直接使用这个方法调用刚才的地址就行
// 获取appStore版本号 NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"987953868"]; [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); }
最后打印出来的字典中就包含 版本号
receiveData={
status = 1;
version = "1.0.0";
}
好了 ,有什么问题 欢迎加群讨论
苹果开发群 :414319235 欢迎加入 欢迎讨论问题
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-10 06:04:45