swift - RealityKit 应用程序和较低的 iOS 部署目标

标签 swift augmented-reality realitykit

我有一个部署目标为 iOS 10+ 的 iOS 应用程序,我需要添加一些仅依赖于 RealityKit 的功能以显示给 iOS 版本为 13+ 的用户,该应用程序在真实设备上编译并成功运行,但问题在存档以上传到 AppStore 时,它​​会生成一个 Swift 文件并说:

// "No such module RealityKit"

确定原因与 iOS 版本 <13.0 有关,但我无法编辑该文件(将 canImport 添加到 RealityKit)它是只读的。

我的问题是如何解决这个问题并使其在低版本支持下成功归档?

这是一个展示归档时问题的演示 Demo .

enter image description here

最佳答案

首先:

请勿在您的存档中包含 Reality Composer 的 .rcproject 文件以供分发。 .rcproject 包包含带有 iOS 13.0+ 类的代码,结构和枚举。相反,为您的项目提供 USDZ文件。

其次:

要允许 iOS 13+ 用户使用 RealityKit 功能,但仍允许非 AR 用户从 iOS 10.0 开始运行此应用程序,请使用以下代码(请考虑,这是一个模拟器版本):

import UIKit

#if canImport(RealityKit) && TARGET_OS_SIMULATOR

import RealityKit

@available(iOS 13.0, *)
class ViewController: UIViewController {
    
    var arView = ARView(frame: .zero)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        arView.frame = self.view.frame
        self.view.addSubview(arView)
                
        let entity = ModelEntity(mesh: .generateBox(size: 0.1))
        let anchor = AnchorEntity(world: [0,0,-2])
        anchor.addChild(entity)
        arView.scene.anchors.append(anchor)
    }
}    
#else

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

#endif

部署目标是 iOS 10.0:

enter image description here

第三:

当发布到 AppStore 时(如果我们的部署目标低于 iOS 13.0),我们必须在build设置中将此框架的导入弱链接(这是因为 RealityKit 已深度集成在 iOS 和 Xcode 中)。

因此,转到 Build Settings –> Linking -> Other linker Flags

双击它,按+,然后粘贴following command :

-weak_framework RealityKit -weak_framework Combine

enter image description here

附言在 Xcode 13.3 中,有一个项目设置也可以提供帮助

OTHER_LDFLAGS = -weak_framework RealityFoundation

第四点:

因此,转到Build Settings –> Framework Search Paths

然后输入以下命令:

$(SRCROOT)

它必须是递归的

enter image description here

第五次

存档窗口:

enter image description here

关于swift - RealityKit 应用程序和较低的 iOS 部署目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71000365/

相关文章:

ios - 如何关闭导航栏中文本字段调用的键盘?

c# - 一旦 ARCore 在 Unity 应用程序中加载,文本就会消失

c++ - 如何使移动检测到的手和指尖像鼠标一样与 Qt GUI 交互?

swift - 如何计算两个 AnchorEntities 之间的距离?

swift - ARKit – 将场景保存为 USDZ?

ios - 触摸时添加和删除 SKPhysicsJointPin 的混淆问题

ios - 可以在 Swift 中的 firebase 浏览器中看到的图像的 URL

ios - 委托(delegate)通过父 View Controller 和嵌入式 View Controller 捕获了什么?

unity-game-engine - 如何在 Hololens 模拟器中测试 Air Tap 手势?

computer-vision - ARKit 摄影测量