app升级,获取AppStore版本号和本地版本号

1.获取远程版本号

代码:比如随便新建一个demo

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 获取appStore版本号  最后一串数字就是当前app在AppStore上面的唯一id
    NSString *url = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"414478124"];
    [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);
    
}


说明:上面代码中的这行代码后面那串数字,就是app在AppStore上面的唯一id

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

比如随便在AppStore上面打开一个APP,复制其链接(只要链接中的数字)

https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8





结果:


2.获取本地版本号

NSString* thisVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString*)kCFBundleVersionKey];


3.跳转到AppStore下载

//APPid就是上面的那串数字

 

NSString  *urlStr = [NSStringstringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",APPID];

   

   NSURL *url = [NSURLURLWithString:urlStr];

    [[UIApplicationsharedApplication]openURL:url];


  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值