美文网首页iOS经验总结
iOS16 和 Xcode14 适配中遇到的问题以及解决办法

iOS16 和 Xcode14 适配中遇到的问题以及解决办法

作者: 李丘 | 来源:发表于2022-09-26 10:23 被阅读0次

    升级完 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变化    
    }
    

    相关文章

      网友评论

        本文标题:iOS16 和 Xcode14 适配中遇到的问题以及解决办法

        本文链接:https://www.haomeiwen.com/subject/yyitartx.html