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?
四.異常斷點
現象:運行起來之后,每次都會在?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
http://www.lxweimin.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
橫豎屏適配: