IOS检查版本更新
来源:互联网 发布:mnist数据集 编辑:程序博客网 时间:2024/05/29 06:36
iOS的版本号, 一个叫做Version, 一个叫做Build.
获得Version ,
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
获得build号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 以下方法
先获取最新的版本号
再获取当前软件的版本号
最后进行比较
- (void)checkVersionUpdate{ //同步请求 JSON方法获取数据 NSError *error; NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", kAppId]; NSURL *url = [NSURL URLWithString:urlStr]; NSURLRequest *resquest = [NSURLRequest requestWithURL:url]; NSData *response = [NSURLConnection sendSynchronousRequest:resquest returningResponse:nil error:nil]; NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; if (error) { DLog(@"error: = %@", [error description]); return ; } NSArray *resultArray = [appInfoDic objectForKey:@"results"]; if (![resultArray count]) { DLog(@"error: resultArray == nil"); return; } NSDictionary *infoDic = [resultArray objectAtIndex:0]; NSString *lastVersion = [infoDic objectForKey:@"version"]; NSString *trackViewUrl = [infoDic objectForKey:@"trackViewUrl"]; NSString *trackName = [infoDic objectForKey:@"trackName"]; //获取此应用的版本号 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDict objectForKey:@" CFBundleShortVersionString"]; double doubleCurrentVersion = [currentVersion doubleValue]; double doubleUpdateVersion = [lastVersion doubleValue]; //比较 NSString *titleStr = [NSString stringWithFormat:@"检查更新:%@", trackName]; if (doubleCurrentVersion < doubleUpdateVersion) { NSString *messagestr = [NSString stringWithFormat:@"发现新版本:%@, 是否升级?", lastVersion]; UIAlertView *alter = [[UIAlertView alloc] initWithTitle:titleStr message:messagestr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"升级", nil]; alter.tag = [kAppId intValue]; [alter show]; }else{ UIAlertView *alter = [[UIAlertView alloc] initWithTitle:titleStr message:@"暂无新版本"delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil]; alter.tag = [kAppId intValue]+1; [alter show]; }}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (alertView.tag == [kAppId intValue]) { if (buttonIndex == 1) { //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:_trackViewUrl]]; } }}
3 0
- ios检查版本更新
- ios检查版本更新
- IOS 版本检查更新
- ios检查版本更新
- ios检查版本更新
- ios检查版本更新
- ios检查版本更新
- iOS检查版本更新
- IOS 检查版本更新
- IOS 检查版本更新
- iOS 版本检查更新
- ios检查版本更新
- IOS检查版本更新
- ios版本检查更新
- ios 实现版本更新检查
- ios 实现版本更新检查
- ios 实现版本更新检查
- iOS自定义版本更新检查
- PHP加密解密字符串
- yii2.0源码实现csrf验证
- 在C语言头文件中,#ifndef、#define、#endif的作用?
- Bitmap和Base64的相互转换
- GATT Profile 简介
- IOS检查版本更新
- jquery.Jcrop API详解
- Tinker 热修复 demo 使用指南
- static class 静态类(Java)
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- Unreal Engine 4 —— 使用ProceduralMeshComponent实现模型实时切割
- CentOS 关闭防火墙和SELINUX配置
- opacity兼容ie8
- /etc/ld.so.conf 动态库