ios - ARKit 平面检测 - 类型 'ARView' 的值没有成员 'session'

标签 ios swift augmented-reality arkit realitykit

我正在尝试将平面检测添加到一个简单的 ARKit 应用程序中。我想将图片放在垂直平面上。

所以首先我需要检测平面,然后我可以添加我在 RealityKit 中创建的对象 anchor 。

但是问题是我不确定使用 ARKit 3 和 Xcode 11 检测飞机并将其添加到我的场景的正确方法。

它应该像这样简单:

import ARKit
import RealityKit

@IBOutlet var arView: ARView!

override func viewDidLoad() {
    super.viewDidLoad()

    let arConfiguration = ARWorldTrackingConfiguration()
    arConfiguration.planeDetection = .horizontal
    arView.session.run(arConfiguration)
} 

但是我得到以下错误:

Value of type 'ARView' has no member 'session'

我什至尝试了以下 Apple 从他们的 WWDC 演示 (4:27) 中用作示例的内容,

Apple Demo !

let anchor = AnchorEntity(plane: .verticle, minimumBounds: [0.2, 0.2])
arView.scene.addAnchor(anchor)

但我在尝试创建 AnchorEntity 时遇到以下错误

Expression type 'AnchorEntity' is ambiguous without more context

import UIKit
import RealityKit
import ARKit

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Create a session configuration
    }

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

    func addFrame() {
        // Load the "Box" scene from the "Experience" Reality File
        let boxAnchor = try! Experience.loadBox()

        // Add the box anchor to the scene
        arView.scene.anchors.append(boxAnchor)
    }
}

最佳答案

如果您的构建目的地设置为模拟器,您会收到此错误。您需要选择实际设备或通用 iOS 设备。

我已经在这上面撞了好几次了,现在添加以下评论

    // If the following line fails to compile "Value of type 'ARView' has no member 'session'"
    // You need to select a Real Device or Generic iOS Device and not a simulator
    arView.session.run(configuration)

关于ios - ARKit 平面检测 - 类型 'ARView' 的值没有成员 'session',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56973063/

相关文章:

ios - X 天后删除核心数据

react-native - WebXR 在 React Native WebView 组件中不起作用

augmented-reality - 如何使用 Reality 套件在屏幕前设置实体?

ios - 如何在 iOS 中获取谷歌地图的快照

android - 当用户离线时,Firebase Auth session 会持续多长时间?

swift - 在 View Controller 之间传递数据使用从导航 Controller 中嵌入的 View 到 tabbarcontroller 的 segue

ios - 如何在 Alamofire 中使用 NetworkReachabilityManager

php - objective-c /php session ?

ios - 如何删除以 NSLog iOS 开头的行?

ios - Unity-阴影参差不齐,没有解决方案?