iOS 版本检测更新

#pragma mark - 检查更新
- (void)checkVersion
{
    if ([AppID length] < 1) {
        return;
    }
    
    NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",AppID];
    NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
    [urlRequest setURL:[NSURL URLWithString:url]];
    [urlRequest setHTTPMethod:@"POST"];
    
    NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
    NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];
    
    NSArray *infoArr = [jsonDic objectForKey:@"results"];
    if ([infoArr count]) {
        NSDictionary *releaseInfo = [infoArr objectAtIndex:0];
        NSString *appStoreVersion = [releaseInfo objectForKey:@"version"];
        
        // 这里显示的是appstore 上面设置的号码.
        NSLog(@"appstore 版本为:%@ \n 当前版本为:%@",appStoreVersion,VERSION);
        
        if ([VERSION compare: appStoreVersion] == NSOrderedAscending) {
            // 弹窗
            NSArray *items = @[MMItemMake(@"立即更新", MMItemTypeHighlight, ^(NSInteger index) {
                NSURL *url = [NSURL URLWithString:DownloadUrl];
                NSLog(@"跳转下载地址 : %@", DownloadUrl);
                [[UIApplication sharedApplication] openURL:url];
            }),MMItemMake(@"稍后提醒", MMItemTypeNormal, nil)];
            
            [[[MMAlertView alloc] initWithTitle:@"提示" detail:@"出新版本啦,快点更新吧!" items:items]showWithBlock:nil];
            
        }
    }
}

你可能感兴趣的:(iOS 版本检测更新)