iOS16 和 Xcode14 適配中遇到的問題以及解決辦法

升級完 Xcode14 和 iOS16 之后,遇到了一些問題,網絡上的解決辦法也比較少,特此記錄一下

如果在工作中遇到一些疑難雜癥,在一般的網絡搜索中找不到解決辦法的時候,可以去蘋果的 Developer Forums 查找一下,這里更加全面,更加全球化,總會找到跟你遇到同樣問題的人,以及找到相應的解決辦法。

Target 簽名報錯

升級Xcode14,運行項目報了以下錯,尤其是組件化的項目:

Signing for "xxxxxx" requires a development team. Select a development team in the Signing & Capabilities editor.

有以下三個解決辦法:

方法一:

每一個組件手動選擇 developer team,與主工程一致。

方法二:

在 Podfile 文件 中設置你的開發者的Team ID

post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings["DEVELOPMENT_TEAM"] = "Your Team ID"
         end
    end
  end
end
方法三:

在 Podfile 文件 中設置 CODE_SIGN_IDENTITY (推薦此方法)

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
            config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
            config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
        end
    end
end

APP啟動慢

解決完組件間的簽名問題,順利運行項目,然而在連接Xcode的時候,運行APP特別慢,加載半天都進不去APP首頁。

解決辦法:

使用以下命令打開 DeviceSupport 所在文件夾,刪掉所有版本的 DeviceSupport

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

如果用真機調試的時候發現報錯了

Could not locate device support files. This xxx is running iOS xxx, which may not be supported by this version of Xcode.

重新添加相應版本的 DeviceSupport 即可,可以在下面的倉庫中找到相應的 DeviceSupport 版本:

iOS DeviceSupport

異常斷點

終于跟以前一樣成功運行項目,然而運行起來之后,每次都會在 AppDelegate 中斷點,報以下異常:

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

這種情況是開了全局異常斷點,去掉即可。

Exceptions.png

橫豎屏適配

if (@available(iOS 16.0, *)) {
            
    NSArray *scenes = [UIApplication sharedApplication].connectedScenes.allObjects;
            
    UIWindowScene *scene = scenes.firstObject;
    scene.delegate = self;
            
    UIWindowSceneGeometryPreferencesIOS *preferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskLandscapeRight];
            
    [scene requestGeometryUpdateWithPreferences:preferences errorHandler:nil];
            
} else {
            
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
        
#pragma mark - 代理

- (void)windowScene:(UIWindowScene *)windowScene didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation traitCollection:(UITraitCollection *)previousTraitCollection  API_AVAILABLE(ios(13.0)){

    //相應的UI變化    
}
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容