Xcode16 避坑

Xcode16 避坑

原文地址

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 >= 180000
    if (@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 编辑支持的设备方向时崩溃

图片)

旧版本创建的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). 重新打开项目,可以看到支持的设备方向已经清空了,现在可以重新选择支持的方向

图片

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

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.absoluteString

FileManager.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无法定位到具体的崩溃地址
在这里插入图片描述

解决方法:

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)’.
图片描述

原因未知

解决方法 :

sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService

xcrun simctl erase all


        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
  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
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nick5683

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值