首页 > 移动平台 > 详细

iOS 获取appstore 版本号

时间:2015-08-12 16:51:11      阅读:328      评论:0      收藏:0      [点我收藏+]

项目上线以后一般都涉及到升级,那么iOS 如何从appstore获取到版本号


其实很简单

    NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"987953868"];

其中 最后一串数字就是当前app的唯一id。 这个id如何得到,百度一下 很简单


然后我们只需要调用这个 地址,就会返回当前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 版本号

原文:http://blog.csdn.net/lwjok2007/article/details/47446049

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!