项目上线以后一般都涉及到升级。那么iOS 怎样从appstore获取到版本
事实上非常easy
NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup? id=%@",@"987953868"];
当中 最后一串数字就是当前app的唯一id。 这个id怎样得到,百度一下 非常easy
然后我们仅仅须要调用这个 地址。就会返回当前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-10-14 20:14:36