美文网首页iOS技术大前端开发
Xcode14&iOS16适配总结文档

Xcode14&iOS16适配总结文档

作者: 钟华威 | 来源:发表于2022-11-24 13:52 被阅读0次

    Xcode14&iOS16适配文档

    一.Pod工程中的Bundle target签名报错

    · 方法一:手动选择Pod工程中的Bundle target 签名中的Team,与主工程一致

    · 方法二: 在 Podfile文件中设置你的开发者的Team ID

    post_installdo|installer|

      installer.generated_projects.eachdo|project|

        project.targets.eachdo|target|

          target.build_configurations.eachdo|config|

            config.build_settings["DEVELOPMENT_TEAM"] ="Your Team ID"

          end

        end

      end

    end

    · 方法三: 在 Podfile 文件 中设置 CODE_SIGN_IDENTITY 为空来避免报错,这是目前在用的,也是最简单的方法(推荐此方法)

    post_install do |installer|

    installer.generated_projects.each do |project|

    project.targets.each do |target|

    target.build_configurations.each do |config|

    config.build_settings['CODE_SIGN_IDENTITY'] = ''

    end

    end

    end

    end

    使用Xcode14打出来的包,在iOS12.2以下的系统发生崩溃

    方法一:

    在Build Phases -> Link Binary With Librarires 里面添加 libswiftCoreGraphics.tbd。否则xcode14打出来的包,在iOS12.2以下的系统找不到libswiftCoreGraphics.dylib而发生崩溃。

    方法二:官方推荐的方法

    Build Setting -> other linkflags 添加 -Wl,-weak-lswiftCoreGraphics 

    方法三:Xcode14.1官方已经修复,下载Xcode14.1就可以

    .APP启动慢

    解决完组件间的签名问题,顺利运行项目,然而在连接Xcode的时候,运行APP特别慢,加载半天都进不去APP首页。

    解决办法:

    使用以下命令打开 DeviceSupport 所在文件夹,删掉所有版本的 DeviceSupport

    open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

    如果用真机调试的时候发现报错了

    Could not locate device support files.This xxx isrunning iOS xxx,which may not be supported by thisversion of Xcode.

    重新添加相应版本的 DeviceSupport 即可,可以在下面的仓库中找到相应的 DeviceSupport 

    版本: https://gitee.com/Han0/iOSDeviceSupport#https://gitee.com/link?target=https%3A%2F%2Fcode.aliyun.com%2Fhanjinjun%2FiOSDeviceSupoort%2Fraw%2Fmaster%2FDeviceSupport%2F15.7.zip

    异常断点

    现象:运行起来之后,每次都会在 AppDelegate 中断点,报以下异常:

    Thread 1: "[<_UINavigationBarContentViewLayout 0x13b107470> valueForUndefinedKey:]: this class is not key value coding-compliant for the key inlineTitleView."

    方法一:这种情况是开了全局异常断点,去掉即可。

    方法二:在全局断点上添加下面的条件

    !(BOOL)[(id)[$arg1 reason] containsString:@"_UINavigationBarContentViewLayout"]

    方法三:添加下面代码到工程,并在启动之后马上调用

    #import  

    @interface Xcode14Fixer : NSObject

    @end

    @implementation Xcode14Fixer 

    + (void)load { 

    Class cls = NSClassFromString(@"_UINavigationBarContentViewLayout");

      SEL selector = @selector(valueForUndefinedKey:); 

    Method impMethod = class_getInstanceMethod([self class], selector);

      if (impMethod) { 

    class_addMethod(cls, selector, method_getImplementation(impMethod), method_getTypeEncoding(impMethod));

    }

    - (id)valueForUndefinedKey:(NSString *)key { 

    return nil; 

    }

    @end

    五.横竖屏适配

    [UIDevice currentDevice] 使用setValue:forKey:的方式在iOS16上面已经不可用,继而要使用UIWindowScene里面的函数请求

    if (@available(iOS 16.0, *)) {

    UIWindowScene *windowScene = (UIWindowScene *)[[[UIApplication sharedApplication] connectedScenes] allObjects].firstObject;

    UIWindowSceneGeometryPreferencesIOS *perference = [[UIWindowSceneGeometryPreferencesIOS alloc] init];

    perference.interfaceOrientations = 1 << deviceOrientation;

    [windowScene requestGeometryUpdateWithPreferences:perference errorHandler:^(NSError * _Nonnull error) {

    NSLog(@"error--%@", error);

    }];

    } else {

    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:deviceOrientation] forKey:@"orientation"];

    [UIViewController attemptRotationToDeviceOrientation];

    }

    /****兼容没有升级到Xcode14的写法**/

            @try{

                   NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];

                   UIWindowScene*ws = (UIWindowScene*)array[0];

                   ClassGeometryPreferences =NSClassFromString(@"UIWindowSceneGeometryPreferencesIOS");

                   idgeometryPreferences = [[GeometryPreferencesalloc]init];

                   [geometryPreferencessetValue:@(UIInterfaceOrientationMaskLandscapeRight) forKey:@"interfaceOrientations"];

                   SEL sel_method = NSSelectorFromString(@"requestGeometryUpdateWithPreferences:errorHandler:");

                   void(^ErrorBlock)(NSError*err) = ^(NSError*err){

                       //业务代码

                   };

                   if([wsrespondsToSelector:sel_method]) {

                       (((void(*)(id,SEL,id,id))[wsmethodForSelector:sel_method])(ws, sel_method,geometryPreferences,ErrorBlock));

                   }

               }@catch(NSException *exception) {

                   //异常处理

               }@finally{

                   //异常处理

               }

    iOS16手机开启开发者模式"developer mode disable"

    iOS16手机未打开开发者模式时:

    1、Xcode 无法选中 iOS16的设备,报错:developer mode disable

    2、无法打开升级前编译的App

    · 解决办法:在你的iPhone中操作调试手机--设置--隐私与安全--(滑动到最底部)开发者模式--开启开发者模式(需要重启手机)

    .Xcode14 UIViewController在dealloc时发生崩溃

    iOS16调试的时候报错

    Application circumvented objective-c runtime dealloc initiation for <%s> object并崩溃

    原因是:IOS16 苹果不允许重写系统控件分类(Categroy)中重写 + (void)initialize方法

    8.旋转相关

    8.1、屏幕旋转通知在iOS16无法处触发

    需要重写UIViewController的viewWillTransitionToSize:withTransitionCoordinator:,在此函数里面处理UI。

    8.2、iOS16 使用过YYTextView之后无法旋转屏幕

    使用过UITextView之后,再调用函数 requestGeometryUpdateWithPreferences:geometryPreferences errorHandler: 请求无效,无法旋转屏幕

    分析:打印所有的connectedScenes

    使用YYTextView之前

    使用YYTextView之后

    解决方案:

    问题是当前的UIWindowScene里面多了一层YYTextView添加的YYTextEffectWindow,去掉这一层window就可以了。

    9.隐私权限增强

    隐私权限增强,如通过 UIDevice 获取设备名称时,无法获取用户的信息,只能获取设备对应的名称

    比如之前获取的设备信息“XXX iPhone13  pro max”,在iOS16后只能获取到“iPhone13  pro max”,不再包含用户信息

    10.剪贴板内容获取

    iOS 16 中通过 UIPasteboard 获取剪贴板中的内容时,系统会弹出对话框提醒用户是否允许粘贴。如果不想显示该对话框,建议使用新增的 UIPasteControl 控件来读取剪贴板的内容。

    11.iOS16新增的控件或api的改动

    11.1、新增控件

    1、UICalendarView:新增 UICalendarView,可以显示日期并支持单选与多选日期

    2、UIEditMenuInteraction:新增一个交互 UIEditMenuInteraction,用于取代 UIMenuController 与 UIMenuItem。

    3、UIFindInteraction:新增一个交互 UIFindInteraction 用于文本内容查找与替换。

    4、UIPasteControl:新增 UIPasteControl 用于读取剪贴板中的内容,否则跨 App 读取时会弹出对话框让用户进行选择是否同意

    5、LARightStore:新增LARightStore 用于存储与获取 keychain 中的数据。

    6、Live Activity:支持 Live Activity,可以理解为一种特殊的锁屏界面显示的 Widget。

    11.2、api改动

    1、UIImage 增加了新的构造函数用于支持 SF Symbols 最新版中增加的类别 Variable

    2、UINavigationItem 增加了一个属性style用于描述 UINavigationItem 在 UINavigationBar 上的布局;增加了一个属性backAction用于实现当前 UIViewController 的返回按钮事件;增加了一个属性titleMenuProvider用于给当前导航栏的标题添加操作菜单。

    3、UIFont增加了 3 种新的宽度样式:compressed、condensed与expanded,加上默认的standard,目前 UIFont 共有 4 种字体宽度。宽度大小关系为:expanded>standard>condensed>compressed

    4、UIPageControl:UIPageControl 支持垂直显示并可以设置指示器与当前页的图片

    5、UITableView 与 UICollectionView 在使用 Cell Content Configuration 时支持使用 UIHostingConfiguration 包装 SwiftUI 代码定义 Cell 的内容

    6、UISheetPresentationController 支持自定义显示的 UIViewController 的大小

    7、UIDevice 不再支持通过setValue()方法设置设备的方向,替换为 UIWindowScene 的requestGeometryUpdate()方法。

    8、UIMenu 支持设置尺寸,分别为small、medium与large。

    9、隐私权限增强,如通过 UIDevice 获取设备名称时,无法获取用户的信息,只能获取设备对应的名称。

    12.遇到的问题

    12.1、Pod工程中的Bundle target签名报错(在develop分支上福才已经添加teamId的形式解决我在master分支上测试)

    12.2 编译错误:

    'WXApi' has different definitions in different modules; first difference is defined here found method

    解决方案:

    先是unpair device->退出Xcode->去到目录~/Library/Developer/Xcode/iOS DeviceSupport ,删除该目录下的所有文件

    12.3、UIBarButtonItem使用initWithTitle:初始化时会CPU直接100%

    解决方案:

    在UIBarButtonItem+Category扩展中新增这个方法覆盖原来的方法

    参考资料:

    https://blog.csdn.net/overstep1024/article/details/113629854

    https://www.jianshu.com/p/09fd4751aaf9

    https://rapidsu.cn/articles/1300

    在模拟器运行打全局断点适配:

    https://developer.apple.com/forums/thread/712240

    https://stackoverflow.com/questions/73350251/xcode-14-beta-5-throws-an-exception

    横竖屏适配:

    https://www.jianshu.com/p/ff6ed9de906d

    相关文章

      网友评论

        本文标题:Xcode14&iOS16适配总结文档

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