Xcode14&iOS16適配總結文檔

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

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

橫豎屏適配:

http://www.lxweimin.com/p/ff6ed9de906d

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,837評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,196評論 3 414
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,688評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,654評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,456評論 6 406
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,955評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,044評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,195評論 0 287
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,725評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,608評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,802評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,318評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,048評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,422評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,673評論 1 281
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,424評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,762評論 2 372

推薦閱讀更多精彩內容