iOS 获取appstore 版本
生活随笔
收集整理的這篇文章主要介紹了
iOS 获取appstore 版本
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
項目上線以后一般都涉及到升級。那么iOS 怎樣從appstore獲取到版本
事實上非常easy
NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"987953868"];
當中 最后一串數(shù)字就是當前app的唯一id。 這個id怎樣得到,百度一下 非常easy
然后我們僅僅須要調(diào)用這個 地址。就會返回當前app的一些信息,當中就包含appstore上的版本(前提是項目已經(jīng)上線到appstore)
我們把獲取的過程做了整理 大家直接使用這種方法調(diào)用剛才的地址即可
// 獲取appStore版本
NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"987953868"];
[self Postpath:url];
#pragma mark -- 獲取數(shù)據(jù)
-(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";
}
好了 ,有什么問題 歡迎加群討論
蘋果開發(fā)群 :414319235 歡迎增加 歡迎討論問題
總結(jié)
以上是生活随笔為你收集整理的iOS 获取appstore 版本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用富文本OHAttributedLab
- 下一篇: 如何使用win7自带的备份还原以及创建系