问题描述
为 xcode Simulator 构建时是否可以禁用 RealityKit/ARKit/AR?这样我就可以设计/更改非 ar 相关页面。
我想更改我的主页,添加不同的部分和样式。主页与 ARKit/Reality Kit 无关,但我没有随身携带实体设备。
错误表明各种 RealityKit/ARKit 函数未定义或不存在。就像 ARView 没有成员 .occlusion。
主页根本不需要AR,是否可以构建和运行模拟器,甚至可以在没有物理(启用AR)设备的情况下进行预览?
解决方法
您可以使用 Conditional Compilation Block,如 Swift 编程手册中所述:
class SubclassedARView : ARView {
var configuration: ARWorldTrackingConfiguration()
var runOptions: ARSession.RunOptions()
init() {
#if !targetEnvironment(simulator)
// Code here is only compiled when building to a real or generic device.
// This is the place where you should add your RealityKit specific
// code,or at least the code that gives build-time errors in Xcode.
// An example of a problematic method:
session.run(configuration,options: runOptions)
#endif
}
}