2019-12-30-iOS 13适配-2019

iOS技术成长之路

Posted by DM on December 30, 2019

1. 安装时,加入 Xcode11.3 后 原 xcode 会安装开发工具插件时候出现

点击安装插件之后会出现

目前没找到解决方案。只能在一个 mac 电脑上安装使用一个版本。

2.编译时,会出现 libstdc++.6.0.9.tbd 文件找不到的错误提示,需要将文件重新放入工程 c++文件目录下。

3.运行时,会出现另一个错误:

NSInteger numberOfBeforeSection = [_update[@""] numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section];

此方法目前在 Xcode11.3 里调用 UICollectionView 方法需要强转成系统类名,即在_update[@”“]加入(UICollectionView *)即可。 如下

NSInteger numberOfBeforeSection = [(UICollectionView *)_update[@""] numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section];

4.接下来就是比较关注的适配暗黑模式了:建议暂时直接关闭暗黑模式,如果有需求时再添加。

//配置方式有两种,单页面配置 和 全局配置
    if (@available(iOS 13.0, *)) {
        self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
单页配置
    将需要配置的 UIViewControler 对象的 overrideUserInterfaceStyle 属性设置成 UIUserInterfaceStyleLight 或者 UIUserInterfaceStyleDark 以强制是某个页面显示为 浅/深色模式

    全局配置
    在工程的Info.plist的中,增加/修改 UIUserInterfaceStyle为UIUserInterfaceStyleLight或UIUserInterfaceStyleDark
————————————————

5.UISearchBar 的页面 crash (可能出现,目前项目中未暴露出来)

因为这一句代码:

UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];

需要进行 ios 13 的适配工作 demo 如下

NSString *version = [UIDevice currentDevice].systemVersion;
      if (version.doubleValue >= 13.0) {
          // 针对 13.0 以上的iOS系统进行处理
          UITextField *searchField;
          NSUInteger numViews = [self.searchBar.subviews count];
          for(int i = 0; i < numViews; i++) {
             if([[self.searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
                 searchField = [self.searchBar.subviews objectAtIndex:i];
             }
          }
          if (searchField) {
            //这里设置相关属性
          }else{}


      } else {
          // 针对 13.0 以下的iOS系统进行处理
          UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];

             if(searchField) {
                //这里设置相关属性

             }else{}
}

以下问题暂时项目中未发现,如出现可参照以下方式更改。

6.uitextfield setvalue forkeypath 方法失效

该方法在 iOS13 已经无效,系统禁止通过 KVC 访问。会导致直接崩溃。修改方法使用 textfild 的 attributePlaceholder 属性即可。

7.所有 present 的界面都会类似于 sarfari 网页视图一样的层叠方式显示。会导致项目部分页面无法横屏 返回无法刷新。在 ios 13 里修改了 vc 的 modalPresentationStyle 的默认值为 -2 暴露出来的问题是

要想解决这个问题很简单。直接设置 present 的 vc 模式为 UIModalPresentationFullScreen(0)即可解决。变更后就会变成之前的跳转模式了。

8.Sign In with Apple

在 iOS 13 里添加了 Sign In with Apple 登录方式,根据苹果官网说明,2020 年 4 月份之前需要所有第三方登录的 app 都需要更新,否则会拒审。具体可看苹果审核规则中的 4.8 章节。 更新细节可以参考这篇文章Sign In with Apple

9.statusbar 修改背景色问题

iOS13 已经去掉了这个方式。

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

新的替换方案为:

-(UIView *)statusBarUIview{
    if(@available(iOS 13,*)){

        int tag = 13004352;

        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        UIView *view = [window viewWithTag:tag];
        if (view) {
            return view;
        }else{
            CGRect statusBarRect = [UIApplication sharedApplication].statusBarFrame;
            UIView *statusBarView = [[UIView alloc]initWithFrame:statusBarRect];
            statusBarView.tag = tag;
            [window addSubview:statusBarView];
            return statusBarView;
        }

    }else{
        UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
        if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
            return statusBar;
        }
    }

    return nil;
}

10.子线程修改界面导致崩溃(比如相册首次授权回调必现,二次授权偶现)

在使用相册时我们会调用 [PHPhotoLibrary requestAuthorization:] 方法获取权限,获取的结果会通过一个带有 PHAuthorizationStatus 信息的 block 进行回调。 解决方案:在 Xcode 中调试运行时,子线程修改界面会有紫色感叹号标出,注意修改成回到主线程即可。