iOS 獲取appstore 版本
阿新 • • 發佈:2017-05-25
地址 sync error nil leaves load app reading mat
當中 最後一串數字就是當前app的唯一id。 這個id怎樣得到,百度一下 非常easy
最後打印出來的字典中就包括 版本
項目上線以後一般都涉及到升級。那麽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 歡迎增加 歡迎討論問題
iOS 獲取appstore 版本