当前位置: 首页 > news >正文

Xcode16 避坑

Xcode16 避坑

Xcode16 避坑

erick_yim

2024-06-17 4,685 阅读3分钟

1、UITabBarController 的 sideBar

iPad 升级到iOS 18 后,底部的 UITabBar 会被系统移动到顶部。(如果你对页面 UI 尺寸做了调整,页面底部可能有空白)

如何把 UITabBar 移到底部?

iPadOS 18.1 + Xcode 16.1 仅仅设置self.mode = UITabBarControllerModeTabBar不起作用

// 在UITabBarController子类里#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000if (@available(iOS 18.0, *)) {if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {self.mode = UITabBarControllerModeTabBar;self.traitOverrides.horizontalSizeClass = UIUserInterfaceSizeClassCompact;[self.view addSubview:self.tabBar];NSString *tabContainerClassName = [NSString stringWithFormat:@"%@%@%@", @"_UITab", @"Container", @"View"];for (UIView *subview in self.view.subviews) {if ([NSStringFromClass(subview.class) isEqualToString:tabContainerClassName]) {[subview setHidden:YES];}}}}
#endif

2、第一次断点po慢,输出 Debugging will be degraded due to missing types.

unable to locate module needed for external types

error:
‘/xxxxx/ModuleCache.noindex/C499AKLJ8KAG/ObjectiveC-1KD62J152BYGO.pcm’ does
not exist

Debugging will be degraded due to missing types. Rebuilding the project will
regenerate the needed module files.warning: (arm64)

Debugging will be degraded due to missing types. Rebuilding the project will
regenerate the needed module files.warning: (arm64)

1. 创建或者编辑文件echo "settings set target.experimental.swift-enable-cxx-interop false" >> ~/.lldbinit
2 重启进程killall lldb-rpc-server
3. 打开Xcode重新debug

似乎在 Build Settings - Build Options里设置 DEBUG_INFORMATION_FORMAT = "dwarf- with-dsym" 有效

XCode15 debugger is working really slow with iOS 17.0.2
forums.developer.apple.com/forums/thre…

3、自定义组件的 maskView 崩溃

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’,
reason: 'Set maskView (<UIView: 0x1155af800; …) to nil before adding it as
a subview of xxx

原因: UIView有自带属性 maskView, iOS 18 对 UIView的maskView
增加了断言,导致如果业务代码里有同名属性可能导致触发该断言。自定义组件相当于重写了系统属性。

解决方法:将自定义组件的 maskView 重名名。

// UIView.h
@interface UIView(UIViewRendering)
@property(nullable, nonatomic,strong) UIView *maskView API_AVAILABLE(ios(8.0));
#end

4、git仓库有大量的staged文件, 导致Xcode Not Responding

当前版本:Xcode Version 16.1 (16B40), 已经向苹果反馈。

出现问题的场景:

1)当前项目初始化了git仓库,有大量的staged文件但是没有提交(比如5000个)。

Xcode重新打开项目时也无响应。其实Xcode在处理文件导致不能操作, 可能10分钟后才处理完毕。

解决方法:git commit 即可

5、Xcode 编辑支持的设备方向时崩溃

![image.png](https://p3-xtjj-sign.byteimg.com/tos-
cn-i-73owjymdk6/ad92e8e238ea4c648aca9d5570169814~tplv-73owjymdk6-jj-
mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgZXJpY2tfeWlt:q75.awebp?rk3s=f64ab15b&x-expires=1760437608&x-signature=J3cWgTPYvu7sD1%2BfIZ%2B1XD36VPQ%3D)

旧版本创建的Xcode项目,支持的设备方向的字段在info.plist文件中,Xcode 16
移除了info.plist中的字段,改为project中配置所以尝试编辑时崩溃。

解决方法:

1). 找到info.plist文件,先备份 2). 右键点击,选择open as source code,删除所有key value,保留如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>

3). 重新打开项目,可以看到支持的设备方向已经清空了,现在可以重新选择支持的方向

![image.png](https://p3-xtjj-sign.byteimg.com/tos-
cn-i-73owjymdk6/55e9e18aca28410d9178fe756e24cc50~tplv-73owjymdk6-jj-
mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgZXJpY2tfeWlt:q75.awebp?rk3s=f64ab15b&x-expires=1760437608&x-signature=EYy1bSY8pGUCG%2BY7p%2Ff2y12r%2BwI%3D)

4). 把需要的key value 重新添加到info.plist里面

这些在项目配置中有的key就不要添加到info.plist,否则修改支持的设备方向还是会崩溃

![image.png](https://p3-xtjj-sign.byteimg.com/tos-
cn-i-73owjymdk6/f81af769f6dd408684d146911a4d22ef~tplv-73owjymdk6-jj-
mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgZXJpY2tfeWlt:q75.awebp?rk3s=f64ab15b&x-expires=1760437608&x-signature=ZlWmlgpJfcslgwthLNBR6BHH3oQ%3D)

6、openURL 废弃 (无法打开微信等第三方APP)

BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to
migrate to the non-deprecated
UIApplication.open(_:options:completionHandler:). Force returning false
(NO).

UIApplication.shared.open(URL) 替换成 UIApplication.shared.open(URL, options: [:], completionHandler: nil)

7、iOS 18 PHAsset URL from requestAVAsset

获取相册文件PHImageManager.default().requestAVAsset(forVideo...)

Xcode 16/15 + iOS 18 返回的absoluteString包含一段奇怪的固定代码
#YnBsaXN0MDDRAQJfEBtSZWNvbW1lbmRlZEZvckltbWVyc2l2ZU1vZGUQAAgLKQAAAAAAAAEBAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAr

PHCachingImageManager().requestAVAsset(  
forVideo: userPhoto.imageAsset,  
options: options  
) { asset, _, _ in  
if let asset = asset as? AVURLAsset {  
print(asset.url.absoluteString)  
// file:///var/mobile/Media/DCIM/100APPLE/IMG_0768.MP4#YnBsaXN0MDDRAQJfEBtSZWNvbW1lbmRlZEZvckltbWVyc2l2ZU1vZGUQAAgLKQAAAAAAAAEBAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAr print(asset.url.relativePath)  
// /var/mobile/Media/DCIM/100APPLE/IMG_0768.MP4
}  
}

检查文件是否存在

let relativePath = someUrl.relativePath
let absolutePath = someUrl.absoluteStringFileManager.default.fileExists(atPath: relativePath) // true
FileManager.default.fileExists(atPath: absolutePath) // false

解决方法: 用relativePath替换absoluteString

8、UICollectionView两次dequeueReusableCell闪退

Xcode 16.2 + iOS 18.3.2, 以下代码会崩溃(神不神奇,意不意外?)

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Identifier1", for: indexPath)
if condition {let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "Identifier2", for: indexPath)return cell2
}
return cell

有崩溃堆栈, 但是xcode无法定位到具体的崩溃地址

![image.png](https://p3-xtjj-sign.byteimg.com/tos-
cn-i-73owjymdk6/400501612cac47c1adb2002c33816a57~tplv-73owjymdk6-jj-
mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgZXJpY2tfeWlt:q75.awebp?rk3s=f64ab15b&x-expires=1760437608&x-signature=BaGmNGLmShIhagUVxrdP0A7DjyY%3D)

解决方法:

if condition {let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "Identifier2", for: indexPath)return cell2
} else {let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Identifier1", for: indexPath)return cell
}

9、Xcode 16.3 Failed to find or create execution context

Xcode 16.3 打开旧项目编译报错:

xxx.xib: Failed to find or create execution context for description
‘<IBCocoaTouchPlatformToolDescription: 0x6000037d36a0> System content for
IBCocoaTouchFramework-ThirteenAndLater <IBScaleFactorDeviceTypeDescription:
0x6000037d3d20> scaleFactor=2x, renderMode.identifier=(null)’.

![image.png](https://p3-xtjj-sign.byteimg.com/tos-
cn-i-73owjymdk6/56002da19bb849fa979cd759d75a78b5~tplv-73owjymdk6-jj-
mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAgZXJpY2tfeWlt:q75.awebp?rk3s=f64ab15b&x-expires=1760437608&x-signature=g6pwBWugT%2B1waIc5686tl3%2B2dco%3D)

原因未知

解决方法 :

sudo killall -9 com.apple.CoreSimulator.CoreSimulatorServicexcrun simctl erase allfor (UIView *subview in self.view.subviews) {if ([NSStringFromClass(subview.class) isEqualToString:tabContainerClassName]) {[subview setHidden:YES];}}}
}

#endif

2、第一次断点po慢,输出 Debugging will be degraded due to missing types.

unable to locate module needed for external types
error: ‘/xxxxx/ModuleCache.noindex/C499AKLJ8KAG/ObjectiveC-1KD62J152BYGO.pcm’ does not exist
Debugging will be degraded due to missing types. Rebuilding the project will regenerate the needed module files.warning: (arm64)

Debugging will be degraded due to missing types. Rebuilding the project will regenerate the needed module files.warning: (arm64)

  1. 创建或者编辑文件 echo “settings set target.experimental.swift-enable-cxx-interop false” >> ~/.lldbinit
    2 重启进程 killall lldb-rpc-server
  2. 打开Xcode重新debug
    似乎在 Build Settings - Build Options里设置 DEBUG_INFORMATION_FORMAT = “dwarf-with-dsym” 有效

XCode15 debugger is working really slow with iOS 17.0.2
forums.developer.apple.com/forums/thre…

3、自定义组件的 maskView 崩溃
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: 'Set maskView (<UIView: 0x1155af800; …) to nil before adding it as a subview of xxx
原因: UIView有自带属性 maskView, iOS 18 对 UIView的maskView 增加了断言,导致如果业务代码里有同名属性可能导致触发该断言。自定义组件相当于重写了系统属性。
解决方法:将自定义组件的 maskView 重名名。
objc 体验AI代码助手 代码解读复制代码// UIView.h
@interface UIView(UIViewRendering)
@property(nullable, nonatomic,strong) UIView *maskView API_AVAILABLE(ios(8.0));
#end

4、git仓库有大量的staged文件, 导致Xcode Not Responding
当前版本:Xcode Version 16.1 (16B40), 已经向苹果反馈。
出现问题的场景:
1)当前项目初始化了git仓库,有大量的staged文件但是没有提交(比如5000个)。
Xcode重新打开项目时也无响应。其实Xcode在处理文件导致不能操作, 可能10分钟后才处理完毕。
解决方法:git commit 即可
5、Xcode 编辑支持的设备方向时崩溃

旧版本创建的Xcode项目,支持的设备方向的字段在info.plist文件中,Xcode 16 移除了info.plist中的字段,改为project中配置所以尝试编辑时崩溃。

解决方法:
1). 找到info.plist文件,先备份
2). 右键点击,选择open as source code,删除所有key value,保留如下
xml 体验AI代码助手 代码解读复制代码<?xml version="1.0" encoding="UTF-8"?>

3). 重新打开项目,可以看到支持的设备方向已经清空了,现在可以重新选择支持的方向

4). 把需要的key value 重新添加到info.plist里面

这些在项目配置中有的key就不要添加到info.plist,否则修改支持的设备方向还是会崩溃

6、openURL 废弃 (无法打开微信等第三方APP)

BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(😃 needs to migrate to the non-deprecated UIApplication.open(:options:completionHandler:). Force returning false (NO).

UIApplication.shared.open(URL)
替换成
UIApplication.shared.open(URL, options: [:], completionHandler: nil)
7、iOS 18 PHAsset URL from requestAVAsset
获取相册文件PHImageManager.default().requestAVAsset(forVideo…)
Xcode 16/15 + iOS 18 返回的absoluteString包含一段奇怪的固定代码
#YnBsaXN0MDDRAQJfEBtSZWNvbW1lbmRlZEZvckltbWVyc2l2ZU1vZGUQAAgLKQAAAAAAAAEBAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAr
swift 体验AI代码助手 代码解读复制代码PHCachingImageManager().requestAVAsset(
forVideo: userPhoto.imageAsset,
options: options
) { asset, _, _ in
if let asset = asset as? AVURLAsset {
print(asset.url.absoluteString)
// file:///var/mobile/Media/DCIM/100APPLE/IMG_0768.MP4#YnBsaXN0MDDRAQJfEBtSZWNvbW1lbmRlZEZvckltbWVyc2l2ZU1vZGUQAAgLKQAAAAAAAAEBAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAr

print(asset.url.relativePath)
// /var/mobile/Media/DCIM/100APPLE/IMG_0768.MP4
}
}

检查文件是否存在
swift 体验AI代码助手 代码解读复制代码let relativePath = someUrl.relativePath
let absolutePath = someUrl.absoluteString

swift 体验AI代码助手 代码解读复制代码FileManager.default.fileExists(atPath: relativePath) // true
FileManager.default.fileExists(atPath: absolutePath) // false

解决方法: 用relativePath替换absoluteString
8、UICollectionView两次dequeueReusableCell闪退
Xcode 16.2 + iOS 18.3.2, 以下代码会崩溃(神不神奇,意不意外?)
swift 体验AI代码助手 代码解读复制代码let cell = collectionView.dequeueReusableCell(withReuseIdentifier: “Identifier1”, for: indexPath)
if condition {
let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: “Identifier2”, for: indexPath)
return cell2
}
return cell

有崩溃堆栈, 但是xcode无法定位到具体的崩溃地址

解决方法:
swift 体验AI代码助手 代码解读复制代码
if condition {
let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: “Identifier2”, for: indexPath)
return cell2
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: “Identifier1”, for: indexPath)
return cell
}

9、Xcode 16.3 Failed to find or create execution context
Xcode 16.3 打开旧项目编译报错:
xxx.xib: Failed to find or create execution context for description ‘<IBCocoaTouchPlatformToolDescription: 0x6000037d36a0> System content for IBCocoaTouchFramework-ThirteenAndLater <IBScaleFactorDeviceTypeDescription: 0x6000037d3d20> scaleFactor=2x, renderMode.identifier=(null)’.

原因未知
解决方法:
zsh 体验AI代码助手 代码解读复制代码sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService

xcrun simctl erase all

作者:erick_yim
链接:https://juejin.cn/post/7381347654767689737
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

http://www.dtcms.com/a/482410.html

相关文章:

  • 论文参考文献引用:规避查重率的有效策略
  • 先楫平台使用Jlink调试
  • 偏置电阻简介
  • 【温室气体数据集】历史温室气体与气溶胶排放数据集 CEDS
  • 家具品牌网站怎么做网站建设印花税
  • 建医疗网站步骤seo优化的技巧
  • 【小白笔记】strip的含义
  • 第136期 谷歌Jules Tools反击Copilot的主导地位:重新定义工作流自动化18
  • Apifox AI 测试用例生成:提高测试效率!
  • 【SpringBoot启动异常】解决@profileActive@相关异常问题
  • 深圳建设营销型网站1做网站的公司
  • 充电桩直流电能表导轨安装 精准计量 智慧运营
  • 像饿了码的网站建站有吗吉林省建设厅官网查询
  • CI/CD产品选型调研
  • 手写MyBatis第107弹:@MapperScan原理与SqlSessionTemplate线程安全机制
  • 专家深度解析5种关键优化方法,助力品牌在AI搜索引擎中脱颖而出
  • 开发实践:基于 PHP+Uniapp 的海外版上门预约系统
  • 迁安网站建设网站没快照
  • 拜尔滤镜详细解释,原理和实践
  • XML Schema 复合类型 - 混合内容
  • C++客服端访问redis
  • 用【WPF+Dlib68】实现 侧脸 眼镜虚拟佩戴 - 用平面图表现空间视觉
  • 重庆网站优化排名上海 企业
  • 网站建设的技术需要多少钱上海软件系统开发公司
  • 汽车用颗粒物传感器:市场趋势、技术革新与行业挑战
  • HICom论文阅读
  • Spring Framework源码解析——ServletContextAware
  • 苏州微网站建设公司做镜像网站
  • OpenStack 网络实现的底层细节-PORT/TAP
  • Chrome 安装失败且提示“无可用的更新” 或 “与服务器的连接意外终止”,Chrome 离线版下载安装教程