Xcode14&iOS16適配文檔
一.Pod工程中的Bundle target簽名報錯
·?方法一:手動選擇Pod工程中的Bundle target?簽名中的Team,與主工程一致
·?方法二:?在?Podfile文件中設(shè)置你的開發(fā)者的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?文件 中設(shè)置?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以下的系統(tǒng)發(fā)生崩潰
方法一:
在Build Phases -> Link Binary With Librarires?里面添加?libswiftCoreGraphics.tbd。否則xcode14打出來的包,在iOS12.2以下的系統(tǒng)找不到libswiftCoreGraphics.dylib而發(fā)生崩潰。
方法二:官方推薦的方法
Build Setting -> other?linkflags 添加 -Wl,-weak-lswiftCoreGraphics?
方法三:Xcode14.1官方已經(jīng)修復(fù),下載Xcode14.1就可以
三.APP啟動慢
解決完組件間的簽名問題,順利運(yùn)行項(xiàng)目,然而在連接Xcode的時候,運(yùn)行APP特別慢,加載半天都進(jìn)不去APP首頁。
解決辦法:
使用以下命令打開?DeviceSupport 所在文件夾,刪掉所有版本的 DeviceSupport
open?/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
如果用真機(jī)調(diào)試的時候發(fā)現(xiàn)報錯了
Could not locate device support files.This xxx?isrunning iOS xxx,which may not be supported?by?thisversion of Xcode.
重新添加相應(yīng)版本的?DeviceSupport 即可,可以在下面的倉庫中找到相應(yīng)的 DeviceSupport?
四.異常斷點(diǎn)
現(xiàn)象:運(yùn)行起來之后,每次都會在?AppDelegate 中斷點(diǎn),報以下異常:
Thread 1: "[<_UINavigationBarContentViewLayout 0x13b107470> valueForUndefinedKey:]: this class is not key value coding-compliant for the key inlineTitleView."
方法一:這種情況是開了全局異常斷點(diǎn),去掉即可。

方法二:在全局?jǐn)帱c(diǎn)上添加下面的條件
!(BOOL)[(id)[$arg1 reason] containsString:@"_UINavigationBarContentViewLayout"]
方法三:添加下面代碼到工程,并在啟動之后馬上調(diào)用
#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上面已經(jīng)不可用,繼而要使用UIWindowScene里面的函數(shù)請求
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){
?? ? ? ? ? ? ? ? ? //業(yè)務(wù)代碼
?? ? ? ? ? ? ? };
?? ? ? ? ? ? ? if([wsrespondsToSelector:sel_method]) {
?? ? ? ? ? ? ? ? ? (((void(*)(id,SEL,id,id))[wsmethodForSelector:sel_method])(ws, sel_method,geometryPreferences,ErrorBlock));
?? ? ? ? ? ? ? }
?? ? ? ? ? }@catch(NSException *exception) {
?? ? ? ? ? ? ? //異常處理
?? ? ? ? ? }@finally{
?? ? ? ? ? ? ? //異常處理
?? ? ? ? ? }
六.iOS16手機(jī)開啟開發(fā)者模式"developer mode disable"
iOS16手機(jī)未打開開發(fā)者模式時:
1、Xcode?無法選中?iOS16的設(shè)備,報錯:developer mode disable
2、無法打開升級前編譯的App
·?解決辦法:在你的iPhone中操作調(diào)試手機(jī)--設(shè)置--隱私與安全--(滑動到最底部)開發(fā)者模式--開啟開發(fā)者模式(需要重啟手機(jī))
七.Xcode14 UIViewController在dealloc時發(fā)生崩潰
iOS16調(diào)試的時候報錯
Application circumvented objective-c runtime dealloc initiation for <%s> object并崩潰
原因是:IOS16 蘋果不允許重寫系統(tǒng)控件分類(Categroy)中重寫 + (void)initialize方法
8.旋轉(zhuǎn)相關(guān)
8.1、屏幕旋轉(zhuǎn)通知在iOS16無法處觸發(fā)
需要重寫UIViewController的viewWillTransitionToSize:withTransitionCoordinator:,在此函數(shù)里面處理UI。
8.2、iOS16 使用過YYTextView之后無法旋轉(zhuǎn)屏幕
使用過UITextView之后,再調(diào)用函數(shù) requestGeometryUpdateWithPreferences:geometryPreferences errorHandler: 請求無效,無法旋轉(zhuǎn)屏幕
分析:打印所有的connectedScenes
使用YYTextView之前

使用YYTextView之后

解決方案:
問題是當(dāng)前的UIWindowScene里面多了一層YYTextView添加的YYTextEffectWindow,去掉這一層window就可以了。
9.隱私權(quán)限增強(qiáng)
隱私權(quán)限增強(qiáng),如通過?UIDevice 獲取設(shè)備名稱時,無法獲取用戶的信息,只能獲取設(shè)備對應(yīng)的名稱
比如之前獲取的設(shè)備信息“XXX?iPhone13 ?pro?max”,在iOS16后只能獲取到“iPhone13 ?pro?max”,不再包含用戶信息
10.剪貼板內(nèi)容獲取
iOS 16?中通過?UIPasteboard?獲取剪貼板中的內(nèi)容時,系統(tǒng)會彈出對話框提醒用戶是否允許粘貼。如果不想顯示該對話框,建議使用新增的?UIPasteControl?控件來讀取剪貼板的內(nèi)容。
11.iOS16新增的控件或api的改動
11.1、新增控件
1、UICalendarView:新增?UICalendarView,可以顯示日期并支持單選與多選日期
2、UIEditMenuInteraction:新增一個交互 UIEditMenuInteraction,用于取代 UIMenuController 與 UIMenuItem。
3、UIFindInteraction:新增一個交互 UIFindInteraction 用于文本內(nèi)容查找與替換。
4、UIPasteControl:新增 UIPasteControl 用于讀取剪貼板中的內(nèi)容,否則跨 App 讀取時會彈出對話框讓用戶進(jìn)行選擇是否同意
5、LARightStore:新增LARightStore 用于存儲與獲取 keychain 中的數(shù)據(jù)。
6、Live Activity:支持 Live Activity,可以理解為一種特殊的鎖屏界面顯示的 Widget。
11.2、api改動
1、UIImage 增加了新的構(gòu)造函數(shù)用于支持 SF Symbols 最新版中增加的類別 Variable
2、UINavigationItem 增加了一個屬性style用于描述 UINavigationItem 在 UINavigationBar 上的布局;增加了一個屬性backAction用于實(shí)現(xiàn)當(dāng)前 UIViewController 的返回按鈕事件;增加了一個屬性titleMenuProvider用于給當(dāng)前導(dǎo)航欄的標(biāo)題添加操作菜單。
3、UIFont增加了?3 種新的寬度樣式:compressed、condensed與expanded,加上默認(rèn)的standard,目前 UIFont 共有 4 種字體寬度。寬度大小關(guān)系為:expanded>standard>condensed>compressed
4、UIPageControl:UIPageControl 支持垂直顯示并可以設(shè)置指示器與當(dāng)前頁的圖片
5、UITableView 與 UICollectionView 在使用 Cell Content Configuration 時支持使用 UIHostingConfiguration 包裝 SwiftUI 代碼定義 Cell 的內(nèi)容
6、UISheetPresentationController 支持自定義顯示的 UIViewController 的大小
7、UIDevice 不再支持通過setValue()方法設(shè)置設(shè)備的方向,替換為 UIWindowScene 的requestGeometryUpdate()方法。
8、UIMenu 支持設(shè)置尺寸,分別為small、medium與large。
9、隱私權(quán)限增強(qiáng),如通過 UIDevice 獲取設(shè)備名稱時,無法獲取用戶的信息,只能獲取設(shè)備對應(yīng)的名稱。
12.遇到的問題
12.1、Pod工程中的Bundle target簽名報錯(在develop分支上,福才已經(jīng)添加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擴(kuò)展中新增這個方法覆蓋原來的方法
參考資料:
https://blog.csdn.net/overstep1024/article/details/113629854
http://www.itdecent.cn/p/09fd4751aaf9
https://rapidsu.cn/articles/1300
在模擬器運(yùn)行打全局?jǐn)帱c(diǎn)適配:
https://developer.apple.com/forums/thread/712240
https://stackoverflow.com/questions/73350251/xcode-14-beta-5-throws-an-exception
橫豎屏適配: