在 xcode Simulator 中构建时禁用 RealityKit/ARKit

问题描述

为 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

    }
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...