iOS 從蘋果商店app版本信息 中國 美國時區差

為什么,寫這篇文章,呃,遇到坑了,記錄一下,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 **

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。