項目上線以後一般都涉及到升級,那麼iOS 如何從appstore獲取到版本號
其實很簡單
NSString *url = [[NSString alloc] initWithFormat:@http://itunes.apple.com/lookup?id=%@,@987953868];
然後我們只需要調用這個 地址,就會返回當前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;
}