iOS版本更新
来源:互联网 发布:剑灵灵剑士卡刀宏数据 编辑:程序博客网 时间:2024/05/21 16:58
版本更新
#pragma mark - 检查版本更新
- (void)checkNewVersion {
// NSString *url = @"https://itunes.apple.com/cn/app/ya-zi-kan-hu-ji-qi-ren/id1067342148?mt=8";
NSString *url = @"http://itunes.apple.com/cn/lookup?id=1067342148"; // ******************根据自己的应用改URL ******************
[GJWHttpTool getWithURL:url params:nilsuccess:^(id json) {
// 请求成功
// 字典接收请求到的JSon
NSDictionary *reslut = [NSJSONSerializationJSONObjectWithData:json options:NSJSONReadingMutableContainers error:nil];
NSDictionary *responseDict = [NSDictionarydictionaryWithDictionary:reslut];
// 解析请求到的JSon
NSArray *results =[responseDictobjectForKey:@"results"];
NSDictionary *finalDict = [resultsfirstObject];
// 获取APP下载地址
NSString *trackViewUrl =[finalDictobjectForKey:@"trackViewUrl"];
updateUrl = [NSURLURLWithString:trackViewUrl];
// 获取官网APP的版本号
NSString *str1 = [finalDictobjectForKey:@"version"];
NSString *version1 = [str1substringFromIndex:2];
// 将版本号字符串转换成float类型
float newVersion = [version1floatValue];
// 获取本地项目版本号
// 拿到项目的infoPlist文件中所有内容
NSDictionary *infoDict = [[NSBundlemainBundle] infoDictionary];
// 获取到当前工程版本号
NSString *str2 = [infoDictobjectForKey:@"CFBundleShortVersionString"];
NSString *version2 = [str2substringFromIndex:2];
// 将版本号字符串转换成float类型
float localVersion =[version2floatValue];
// 对比两处版本号
if (newVersion >localVersion) {
UIAlertView *alert=[[UIAlertViewalloc] initWithTitle:@""message:[NSStringstringWithFormat:@"新版本 %@已发布!",str1]delegate:self.classcancelButtonTitle:@"知道了"otherButtonTitles:nil,nil];
alert.delegate = self;
[alert addButtonWithTitle:@"前往更新"];
[alert show];
alert.tag = 20;
} else {
[[[UIAlertView alloc] initWithTitle:nilmessage:@"已是最高版本"delegate:self.classcancelButtonTitle:@"知道了"otherButtonTitles:nil,nil] show];
}
} failure:^(NSError *error) {
// 返回请求失败的原因
NSLog(@"NSError:%@", error);
}];
}
#pragma mark – UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex ==1 & alertView.tag ==20) {
[[UIApplication sharedApplication] openURL:updateUrl];
}
}
- IOS版本检测,更新版本
- iOS 检测版本更新
- ios检查版本更新
- ios版本更新
- iOS 检测版本更新
- IOS检测版本更新
- IOS版本更新
- ios检查版本更新
- iOS检测版本更新
- iOS 检测版本更新
- ios版本更新
- iOS 版本更新
- iOS 检测版本更新
- IOS 版本更新检测
- iOS 检测版本更新
- iOS 检测版本更新
- iOS --检测更新版本
- IOS 版本检查更新
- while...break 实例
- 博客tag
- ES6笔记
- iOS小demo之将图片压缩到指定尺寸
- win系统 重新启动Apache
- iOS版本更新
- Dagger2
- es6的十大特性
- JS选取DOM元素的方法
- hibernate笔记-002-hibernate5.2使用hbm2ddl.auto错误
- java多线程总结(4)
- java多态
- 对于线性时间筛选素数算法的理解
- 进制转换问题---例如把26进制转为10进制