记录升级Sonoma 的 Xcode15 后MacOS项目需要进行的变动

394 阅读1分钟
  • 系统升级到macos Sonoma 后,提示需要升级Xcode 15 ,之后正常运行项目,出现了许许多多的问题

pod报错

  • 升级 cocoapods
  • 修改podFile如下
post_install do |installer|
  installer.aggregate_targets.each do |target|
    target.xcconfigs.each do |variant, xcconfig|
      xcconfig_path = target.client_root + target.xcconfig_relative_path(variant)
      IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
    end
  end
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.base_configuration_reference.is_a? Xcodeproj::Project::Object::PBXFileReference
        xcconfig_path = config.base_configuration_reference.real_path
        IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
      end
    end
  end
end

NSBeizier增加cgPath属性

  • 会直接编译不通过,提示版本区分符号
if #available**(macOS 14.0, *) {
    let path = bezierPath.cgPath
} else {
    // Fallback on earlier versions
}
  • 暂时未出现其他问题

视图不能正常显示

  • 编译成功后运行项目,直接主视图完全不可见,只显示窗口以及工具栏
  • 查询资料后得知AppKit在14版本系统上对NSView进行了修改
    • 将NSView.clipsToBounds属性的默认值由之前的true变为了false
  • 文档中还提到了可能需要的改动点
    1. 如果想要通过设定NSView的frame 令视图隐藏显示或者令某个子视图离开其父视图bounds时,需要设置其父视图的clipsToBounds为true
    2. 一些使用到重写draw的地方需要将其clipsToBounds为true,否则视图.draw方法就会绘制到view.bounds以外的地方
    3. 在draw方法中使用到 dirtyRect参数来获取位置的地方,应该使用view.bounds来获取,否则,位置可能获取不正确
  • 附变动文档:developer.apple.com/documentati…