Xcode14&iOS16适配总结文档

藏宝库编辑 2024-9-12 23:29:47 28 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


1.png · 方法三: 在 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."
方法一:这种情况是开了全局非常断点,去掉即可。


3.gif 方法二:在全局断点上添加下面的条件
!(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)valueForUndefinedKeyNSString *)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之后


5.gif 办理方案:
标题是当前的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
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 20:29, Processed in 0.233731 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表