踩坑笔记:iOS26适配 + Xcode26升级

0 阅读2分钟

Xcode26升级

背景:最新上传AppStore的ipa,需要 Xcode26(iOS26 SDK)打出来才能发布

场景:Xcode16 -> Xcode26

问题1: iOS12 启动崩溃

环境1:

  • macos26.3+Xcode26.3

  • adhoc包

    • iOS12启动崩溃
    • iOS10 iOS13+都正常
  • appstore+TestFight

    • 所有iOS都正常

环境2:

  • Macos 15.7+Xcode26.3

  • adhoc包

    • 所有系统都正常
  • appstore包

    • 所有系统都正常

问题2: 新包打出来的默认Liquid Grass效果

developer.apple.com/documentati…

需要进行下文的iOS26适配

iOS26适配

重灾区:iOS26.0

  1. Liquid Grass适配
  • 关闭导航栏,按钮,grass效果(和自定义的bar不一致)
  • 关闭present/dismiss动画(不然返回时,动画很不流畅,布局会乱,iOS26.4或之前一个版本看着修复了)
override func present(_ viewControllerToPresent: UIViewController, animated: Bool, completion: (() -> Void)? = nil) {
        super.present(viewControllerToPresent, animated: resolvePresentAnimated(animated), completion: completion)
    }

    override func dismiss(animated: Bool, completion: (() -> Void)? = nil) {
        super.dismiss(animated: resolvePresentAnimated(animated), completion: completion)
    }
// MARK: iOS 26.0 系统 `present` 过渡动画,存在页面布局错乱问题,统一改为无动画。
extension UIViewController {
    func resolvePresentAnimated(_ desired: Bool) -> Bool {
        if #available(iOS 26.1, *) {
            return desired
        }
        if #available(iOS 26.0, *) {
            return false
        }
        return desired
    }
}
  • iOS26 controller present/dismiss后,莫名的偏移回来了

参考:iOS 26 适配|使用 hidesSharedBackground 保持导航栏按钮原有样式

  1. UITabBarContoller适配

问题:developer.apple.com/forums/thre…

// hidesBottomBarWhenPushed = true push 返回动画中,点击tabBar item,莫名丢失了UITabBarContoller

class BaseNavigationController: UINavigationController, UIGestureRecognizerDelegate, UINavigationControllerDelegate {
/// iOS 26(Liquid Glass)下 `hidesBottomBarWhenPushed` 与侧滑返回会导致 TabBar 过早出现,改用手动控制显隐。
    /// 参考:https://developer.apple.com/forums/thread/805740
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        if #available(iOS 26.0, *) {
            let isRootVC = navigationController.viewControllers.first === viewController
            if !isRootVC {
                updateTabBarHidden(true, animated: animated)
            }
        }
    }
    
 func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        interactivePopGestureRecognizer?.isEnabled = true
        if navigationController.viewControllers.count == 1 {
            interactivePopGestureRecognizer?.isEnabled = false
        }
        if #available(iOS 26.0, *) {
            let isRootVC = navigationController.viewControllers.first === viewController
            if isRootVC {
                updateTabBarHidden(false, animated: animated)
            }
        }
    }
    
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if #available(iOS 26.0, *) {
            // iOS 26+:关闭系统 hidesBottomBarWhenPushed,与 willShow/didShow 手动控制 TabBar 配合,避免与 Liquid Glass 行为冲突。
            viewController.hidesBottomBarWhenPushed = false
        } else if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    
  }
  1. UISplitViewController适配

iOS26适配-UISplitViewController配置分栏和分屏背景 使用Xcode26打包出来的,iPad U - 掘金

iOS 26+

  1. UISwitch控件比实际的要大
  2. UIDelegate转化为UISceneDelegate
  3. ……