ios开发之APP检查升级的实现

APP检查升级的实现

#define KStoreAPPID @"972057043"
#pragma mark - 检测更新
- (void)checkVersion {
    /*
     result = {
     resultCount = 0;
     results =     (
     );
     }
     */
    __block NSString *newVersion = nil;
    //NSString *appID = @"972057043";
    NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",KStoreAPPID];
    [LFMyDataService requestWithAFURL:urlString httpMethod:@"GET" params:nil data:nil complection:^(id result) {
        
        NSLog(@"result = %@",result);
        NSArray *results = result[@"results"];
        if (results.count <= 0) {
            NSLog(@"___初始(第一个)版本__");
        }else {
            for (id config in results) {
                newVersion = [config objectForKey:@"version"];
                NSLog(@"通过App Store获得的版本是:%@",newVersion);
            }
        }
        
        //本地获取版本号
        NSString *localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
        NSString *msg = [NSString stringWithFormat:@"你当前版本是:%@,发现新版本:%@。是否下载最新版本", localVersion, newVersion];
        if ([newVersion floatValue] > [localVersion floatValue]) {
            UIAlertView *updateAlert = [[UIAlertView alloc] initWithTitle:@"升级提示" message:msg delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles:@"现在升级", nil];
            updateAlert.tag = 10000;
            [updateAlert show];
        }
        
    }];
    
    
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  {
    
    if (alertView.tag == 10000) {
        
        //软件需要更新提示
        if (buttonIndex == 1) {
            
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%@?mt=8", KStoreAPPID]];
            [[UIApplication sharedApplication] openURL:url];
            
            /*
            //打开itunes 方法二:此方法总提示“无法连接到itunes” 不推荐使用
            //NSString *itunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%i&mt=8";
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%@&mt=8", KStoreAPPID]];
            [[UIApplication sharedApplication] openURL:url];
             */
            
        }
        
    }
    
    
}

如果想知道网络请求AppStore时返回的信息可以打开这个链接:http://itunes.apple.com/cn/lookup?id=465039730



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值