不升级Xcode如何调试iOS 16

  1. 下载iOS16 Support文件

    GitHub - RayJiang16/iOSDeviceSupport: iOS DeviceSupport files (15.0-16.0)

  2. 放置到Xcode DeviceSupport目录重启Xcode即可

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

iOS16手机开启开发者模式

在你的iPhone中操作调试手机→设置→隐私与安全→(滑动到最底部)开发者模式→开启开发者模式(需要重启手机)

修复运行报错 "developer mode disable"

运行遇到的报错 “error: Signing for “XX” requires a development team.”

  1. Build Settings配置(不推荐)

    1. 在Xcode中 选中XX对应的target (in target ‘XX’)
    2. 点击Build Settings 中 在User-Defined (用户自定义那一栏)
    3. 添加CODE_SIGNING_ALLOWED = NO关闭对XX的Code签名
  2. Pod配置CODE_SIGNING_ALLOWED(推荐)

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
          target.build_configurations.each do |config|
              config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
          end
        end
      end
    end
    

    参考如下:

    Xcode 14 build failed with manual code sign and app resource bundles · Issue #11402 · CocoaPods/CocoaPods

  3. Pod配置DEVELOPMENT_TEAM

    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
    

iOS16 横竖屏切换适配

iOS16 之前实现横竖屏切换方式

AppDelegate

AppDelegate 的 .h 文件中添加一个变量来记录是否需要进行横竖屏切换

@property (nonatomic, assign, getter=isLaunchScreen) BOOL launchScreen;    /**< 是否是横屏 */

AppDelegate 的 .m 文件中重写 launchScreensetter 方法

- (void)setLaunchScreen:(BOOL)launchScreen {
    _launchScreen = launchScreen;
    [self application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:nil];
}

并且实现 UIApplicationDelegateapplication:supportedInterfaceOrientationsForWindow: 方法

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (self.isLaunchScreen) {
        // 只支持横屏,并且 Home 按键在右边
        return UIInterfaceOrientationMaskLandscapeRight;
    }
    // 只支持竖屏
    return UIInterfaceOrientationMaskPortrait;
}

在需要实现横竖屏切换的 View