您的位置:首页 > 移动开发 > IOS开发

iOS 版本检测更新方法

2016-06-06 21:31 357 查看
- (void)JudgeAPPVersion
{
    NSString *urlStr =@"https://itunes.apple.com/lookup?id=1050852293";
    NSURL *url = [NSURLURLWithString:urlStr];
    NSURLRequest *req = [NSURLRequestrequestWithURL:url];
    [NSURLConnectionconnectionWithRequest:reqdelegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSError *error;
    id jsonObject = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragmentserror:&error];
    NSDictionary *appInfo = (NSDictionary *)jsonObject;
    NSArray *infoContent = [appInfo objectForKey:@"results"];
    if (infoContent.count <1)
    {
        return;
    }
    NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
    NSDictionary *infoDic = [[NSBundlemainBundle]infoDictionary];
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    if (![version isEqualToString:currentVersion])
    {
        UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"商店有最新版本了"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
        [alert show];
    }
}

#pragma mark -- UIAlertViewDelegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != alertView.cancelButtonIndex)
    {
        [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/cn/app/id1050852293"]];
    }
}

请求返回的app信息字段包括:
{
resultCount = 1;
results = (
{
artistId = 开发者 ID;
artistName = 开发者名称;
price = 0;
isGameCenterEnabled = 0;
kind = software;
languageCodesISO2A = (
EN
);
trackCensoredName = 审查名称;
trackContentRating = 评级;
trackId = 应用程序 ID;
trackName = 应用程序名称;
trackViewUrl = 应用程序介绍网址;
userRatingCount = 用户评级;
userRatingCountForCurrentVersion = 1;
version = 版本号;
wrapperType = software;
}
);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: