美文网首页ios实用开发技巧
关于iOS能否强制更新的问题

关于iOS能否强制更新的问题

作者: 一米押金 | 来源:发表于2018-12-04 11:27 被阅读2024次

iOS,反正作为我,跟后端的火药味反正不轻
就集中在强制更新问题,话语就留在"为什么安卓可以实现,而iOS不可以?"的问题


image.png

我也百度了下强制更新的问题,其实大部分的解决办法,也只是说给用户一个提醒,让它去app商城去下,然后我每次提醒,如果没有下最新的版本,则每次都提醒它去下,如果不下载,点击取消操作,则这个软件就闪退,然后推送也是同理,只能做到如此,至于要做到在软件里更新的操作,我想到的就是"热更新"这个词,至于原生到底能不能行,我说不可以,找证据也没有意义,因为表情包就在上头,我也不想多做解释

目的就是在这里做标记,标记如何强制让用去商城下载的操作,只能这样子了

版本更新

#pragma mark -- 版本更新
-(void)updateVersion{
     // 发送版本更新的请求
     [FCNetWorkManager getVersionInfoCompletionHandle:^(PAVersionModel *responseObj, NSError *error) {
          if (error) {
               [self showErrorTipWith:error.description andStyle:SVProgressHUDStyleDark];
          }else{
               if (responseObj.success) {
                    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
                    // 当前应用软件版本  比如:1.0.1
                    NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
                    ZRLog(@"当前应用软件版本:%@",appCurVersion);
//             我用来测试这个方法行不行得通的一个暂行参数
//                    static NSString *version = @"1.5";
                    //根据每上传成功APPStroe  版本号+1判断是否最新
                    if ([responseObj.data.version.version containsString:appCurVersion]) {
                         // 这里是获取版本成功的情况
                         ZRLog(@"版本已经同步");
                    }else{
                         ZRLog(@"获取版本信息错误:%@", responseObj.message);
                         updateTipView *tipView = [updateTipView view];
                         tipView.frame = self.window.frame;
                         [self.window addSubview:tipView];
                    }
               }
          }
     }];
}
#pragma mark -- updateTipView方法
+(instancetype)view{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

- (IBAction)talkLater:(UIButton *)sender {
    //[self removeFromSuperview];
     exit(0);
}

- (IBAction)nowUpdate:(id)sender {
    NSURL *url = [NSURL URLWithString:@"你的软件在苹果商店的地址"];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication]openURL:url];
        [self removeFromSuperview];
    }else{
        [self showErrorTipWith:@"打不开,请稍后再试!" andStyle:SVProgressHUDStyleDark];
    }
}

其中有些代码例如[self showerror]什么的,这是封装了SVProgress的组件的,你用什么都可以的

然后最后一步

#pramga mark -- appdelegate里的方法
- (void)applicationDidBecomeActive:(UIApplication *)application
{
     [self updateVersion];
}

推送提示

#pragma mark -- 判断是否接受通知 & 是不是第一次启动app
/**
 *  设置远程推送
 */
-(void)setupRemoteNotificationWithViewController:(UIViewController *)vc isFirstLoad:(BOOL)firstLoad{
     // 第一次进app,暂时不设置
     if (firstLoad == YES) {
          ZRLog(@"第一次启动,不做任何处理");
          return;
     }else{
          BOOL isEnable = [AppDelegate isUserNotificationEnable];
          if (isEnable == NO) {
               ZRLog(@"还是没有允许推送");
               UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"关注慧居宝app获得更多更新的小区动态" preferredStyle:UIAlertControllerStyleAlert];
               UIAlertAction *notAllow = [UIAlertAction actionWithTitle:@"不允许" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    exit(0);
               }];
               UIAlertAction *allow = [UIAlertAction actionWithTitle:@"允许" style:UIAlertActionStyleDefault handler:^(UIAlertAction *  action) {
                    // 跳转到页面去开通
                    UIApplication *application = [UIApplication sharedApplication];
                    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                    if ([application canOpenURL:url]) {
                         if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
                              [application openURL:url options:@{} completionHandler:nil];
                         } else {
                              [application openURL:url];
                         }
                    }
               }];
               [alert addAction:notAllow];
               [alert addAction:allow];
               [vc presentViewController:alert animated:YES completion:nil];
          }else if (isEnable == YES){
               ZRLog(@"允许推送,可以进入")
          }
     }
}

+ (BOOL)isUserNotificationEnable { // 判断用户是否允许接收通知
    BOOL isEnable = NO;
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) { // iOS版本 >=8.0 处理逻辑
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        isEnable = (UIUserNotificationTypeNone == setting.types) ? NO : YES;
    } else { // iOS版本 <8.0 处理逻辑
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        isEnable = (UIRemoteNotificationTypeNone == type) ? NO : YES;
    }
    return isEnable;
}

#define LAST_RUN_VERSION_KEY @"last_run_version_of_application"
/**
 * 判断app是否第一次启动或者更新后第一次启动
 */
+ (BOOL) isFirstLoad{
    NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary]
                                objectForKey:@"CFBundleShortVersionString"];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSString *lastRunVersion = [defaults objectForKey:LAST_RUN_VERSION_KEY];

    if (!lastRunVersion) {
        [defaults setObject:currentVersion forKey:LAST_RUN_VERSION_KEY];
        return YES;
    }
    else if (![lastRunVersion isEqualToString:currentVersion]) {
        [defaults setObject:currentVersion forKey:LAST_RUN_VERSION_KEY];
        return YES;
    }
    return NO;
}

布局好后,在appdelegate方法里

    //登录成功后会缓存密码, 根据密码是否存在判断是进入登录界面还是 首页
     //或者不是第一次进app
    BOOL isFirstLoad = [AppDelegate isFirstLoad];
    if ([GGKeyChainManager sharedInstance].password &&
        !isFirstLoad) {
        
        //用于判断从哪个控制器进入的应用 方便以后的退出登录跳转方式
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isFromLoginVC"];
       
         [self setupRemoteNotificationWithViewController:self.window.rootViewController isFirstLoad:isFirstLoad];
    }else{
        
         // 设置远程推送提示
        [self setupRemoteNotificationWithViewController:self.window.rootViewController isFirstLoad:isFirstLoad];
    }

相关文章

  • 关于iOS能否强制更新的问题

    iOS,反正作为我,跟后端的火药味反正不轻就集中在强制更新问题,话语就留在"为什么安卓可以实现,而iOS不可以?"...

  • iOS 版本更新(强制更新)检测问题

    12月1日更新 谢谢,@搬砖技术的提醒需要添加些注意事项: 版本号对比是需要相同的位数的情况下的 比如:位数不同的...

  • 线程通讯详解

    关于子线程能否更新UI的思考线程通讯详解线程池-多线程的高效使用姿势 上文我们说到了关于子线程中能否更新UI的问题...

  • 苹果 iOS 强制更新

    突然客户提出来能不能强制更新,我顿时又进入了懵逼状态,后来发现,强制更新其实并不难,简单的讲讲两种方式吧, 第一种...

  • 苹果iOS 12.1.2动画更新规避侵权,高通回应:仍需禁售

    12月18日消息 今日早晨苹果面向iOS正式版用户推送了iOS 12.1.2版本更新,更新“推出了应用强制退出时的...

  • 关于iOS App 版本控制以及强制更新

    公司刚开始立项一个项目时候,往往项目方向变化比较大,所以项目框架也会经常变更。所以也就存在App的版本控制以及强制...

  • 关于ios app强制横屏问题

    当iphone的某一方向(一般是竖屏)锁定没有开启的时候,当手机横放后,没有写死程序支持方向的程序或者支持横屏的程...

  • iOS版本升级提醒

    关于iOS版本升级,苹果是不允许用户有强制用户升级的提示的,但是为了让用户知道APP更新了,一般APP里面是会有版...

  • iOS 强制版本更新

    版本强制进行更新 强制更新需要在app将要进入前台的时候再一次,调用网络请求的方法

  • iOS 强制版本更新

    github地址:https://github.com/PowerYang/SELUpdateAlert 业务逻辑...

网友评论

    本文标题:关于iOS能否强制更新的问题

    本文链接:https://www.haomeiwen.com/subject/jekmcqtx.html