iOS --版本更新
来源:互联网 发布:ads射频仿真软件 编辑:程序博客网 时间:2024/06/06 03:43
我们开发APP避免不了版本更新,现在我把我个人封装了一个小小的版本更新的东西跟大家分享一下。
首先我们创建一个UIWindow+Extension文件 我们在.H文件里写一个方法并定义几个宏。来设置一些数据信息。
- (void)chooseRootViewController;
#define kHarpyAlertViewTitle @"版本升级"#define kHarpyCancelButtonTitle @"下次再说"#define kHarpyUpdateButtonTitle @"马上升级"#define kAppID @"XXXXXX" //这不用多说明什么
我们在看下.M文件的东西
- (void)chooseRootViewController{ //取出Window UIWindow *window = [UIApplication sharedApplication].keyWindow; //加载info.plist,获取软件当前版本号 NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]; //获取本地版本号 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *sandboxVersion = [defaults valueForKey:@"sandboxVersion"]; //判断是否显示新特性 if ([currentVersion compare:sandboxVersion] == NSOrderedDescending) { // 显示新特性 IntroduceViewController *nfVc = [[IntroduceViewController alloc] init]; // 更新本地保存的版本号 [defaults setValue:currentVersion forKey:@"sandboxVersion"]; //可以做一些新特性东西 }else { // 设置根控制器 window.rootViewController = [ViewController sharedInstance]; //开启线程加载判断版本 [self performSelectorInBackground:@selector(test) withObject:nil]; }}-(void)test{ /** * 版本更新 */ NSString *storeString = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", kAppID]; NSURL *storeURL = [NSURL URLWithString:storeString]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:storeURL]; [request setHTTPMethod:@"GET"]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if ( [data length] > 0 && !error ) { // Success NSDictionary *appData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; dispatch_async(dispatch_get_main_queue(), ^{ // All versions that have been uploaded to the AppStore NSArray *versionsInAppStore = [[appData valueForKey:@"results"] valueForKey:@"version"]; if ( ![versionsInAppStore count] ) { // No versions of app in AppStore return; } else { NSString *currentAppStoreVersion = [versionsInAppStore objectAtIndex:0]; NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]; if ([currentVersion compare:currentAppStoreVersion options:NSNumericSearch] == NSOrderedAscending) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:kHarpyAlertViewTitle message:[NSString stringWithFormat:@"发现新版本(%@),是否更新", currentAppStoreVersion] delegate:self cancelButtonTitle:kHarpyCancelButtonTitle otherButtonTitles:kHarpyUpdateButtonTitle, nil]; alertView.tag = [kAppID intValue]; [alertView show]; } else { MyLog(@"等于"); return; } } }); } }];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if ( alertView.tag == [kAppID intValue] ) { switch ( buttonIndex ) { case 0:{ MyLog(@"----下次再说"); } break; case 1:{ // Update NSString *iTunesString = [NSString stringWithFormat:@"https://itunes.apple.com/app/id%@", kAppID]; NSURL *iTunesURL = [NSURL URLWithString:iTunesString]; [[UIApplication sharedApplication] openURL:iTunesURL]; } break; default: break; } }}其实这个东西很简单的东西。。。。如果对你有帮助 请点赞
0 0
- IOS版本检测,更新版本
- iOS 检测版本更新
- ios检查版本更新
- ios版本更新
- iOS 检测版本更新
- IOS检测版本更新
- IOS版本更新
- ios检查版本更新
- iOS检测版本更新
- iOS 检测版本更新
- ios版本更新
- iOS 版本更新
- iOS 检测版本更新
- IOS 版本更新检测
- iOS 检测版本更新
- iOS 检测版本更新
- iOS --检测更新版本
- IOS 版本检查更新
- 什么是4K视频
- Android 表情功能的完整处理方案
- 谈谈Android 6.0运行时权限理解
- ios中导航栏的使用
- [NFC] 程序设计(NDEF 格式介绍)
- iOS --版本更新
- jlink v8 固件恢复
- android布局属性详解
- Maven简介1
- HDU 4965 (矩阵快速幂)
- java中多态时编译以及运行成员变量及函数分析
- mongodb的聚合函数的$sort 方法运用 和$sort + $match 顺序优化。
- phpstorm注册码以及整个编辑器都使用自定义主题
- android修改软键盘的回车键为搜索键以及点击时执行两次监听事件的问题