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

iOS 检测新版本

2016-03-30 15:05 417 查看
-(void)checkAppUpdate
{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];

NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", JWversionNumber]];
NSString * file =  [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

NSRange substr = [file rangeOfString:@"\"version\":\""];//判断是不是找到字符
NSRange range1 = NSMakeRange(substr.location+substr.length,10);
NSRange substr2 =[file rangeOfString:@"\"" options:nil range:range1];
NSRange range2 = NSMakeRange(substr.location+substr.length, substr2.location-substr.location-substr.length);
NSString *newVersion =[file substringWithRange:range2];
if(![nowVersion isEqualToString:newVersion] && newVersion !=nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"版本有更新"delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
alert.tag = 222;
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"已经是最新版本"delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
alert.tag = 222;
[alert show];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: