判断当前app版本和appstore的版本

http://www.360doc.com/content/15/0728/18/19119980_487992185.shtml

/**
 *   判断app安装版本和商店版本的比较
 */

-(void)judgeAPPVersion
{
//    https://itunes.apple.com/lookup?id=604685049
    
    NSString *urlStr = @"https://itunes.apple.com/lookup?id=604685049";
    NSURL *url = [NSURL URLWithString:urlStr];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    
    NSError *error;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
    NSDictionary *appInfo = (NSDictionary *)jsonObject;
    NSArray *infoContent = [appInfo objectForKey:@"results"];
    NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
    
     NSLog(@"商店的版本是 %@",version);
    
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    NSLog(@"当前的版本是 %@",currentVersion);

 
    if (![version isEqualToString:currentVersion]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"商店有最新版本了" delegate:nil cancelButtonTitle:@"YES" otherButtonTitles:nil,nil];
        [alert show];
    }
    
}

当然你还是可以在页面有个跳转到商店更新APP的接口的按钮滴!
[[ UIApplication sharedApplication ] openURL:[NSURL URLWithString: trackViewUrl ]];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值