iOS 版本检测更新方法

- (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;
}
);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值