为什么,写这篇文章,呃,遇到坑了,记录一下,app刚发布之后,从商店请求过来的app版本信息还是上一个版本的信息。
这是因为中国,美国有时差,你刚在中国区发布的app需要请求链接中国商店的网址,否则会出现一定的时差
http://itunes.apple.com/cn/lookup?id=appId 中国区商店地址
http://itunes.apple.com/lookup?id=appId 美国区商店地址
如果想即使获取到你再中国区发布的app信息,就得用中国区商店地址
源码:
#pragma mark ** 对比app版本 start **
-(void)getAppstoreVersion{
NSString *urlstring = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@""];//美国地区地址
//NSString *urlstring = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",@""];// 中国地区地址
NSURL *url = [NSURL URLWithString:urlstring];
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:(NSDictionary *)sender{
NSString *senderString = [sender[@"version"] stringByReplacingOccurrencesOfString:@"." withString:@""];
DLog(@"网络版本号:%@",senderString);
}
#pragma mark ** 对比app版本 end **