Apple iOS ARKit:“传感器无法提供所需的输入”错误并停止工作

问题描述 投票:5回答:2

我正在开发一个同时使用ARKit和硬件视频解码器的应用程序。一旦解码器开始解码,控制台中就会出现以下错误消息,并阻止跟踪正常工作。

有时,此错误不会显示,应用程序正常工作。经过一些调试后,我发现这个错误只发生在“开始”(启动应用程序后不久)。一旦它通过该点,它在其余时间工作正常。

有谁知道问题是什么或如何绕过它?


2017-08-11 20:48:02.550228-0700 PortalMetal [4037:893878] [] <<<< AVCaptureSession >>>> - [AVCaptureSession _handleServerConnectionDiedNotification] :( 0x1c0007eb0)(pthread:0x170387000)ServerConnectionDied 2017-08-11 20 :48:02.564053-0700 PortalMetal [4037:893747] [会话]会话确实失败并显示错误:错误Domain = com.apple.arkit.error Code = 102“所需传感器失败。” UserInfo = {NSLocalizedFailureReason =传感器未能提供所需的输入。,NSUnderlyingError = 0x1c4c51280 {错误域= AVFoundationErrorDomain代码= -11819“无法完成操作”UserInfo = {NSLocalizedDescription =无法完成操作,NSLocalizedRecoverySuggestion =稍后再试。}}, NSLocalizedRecoverySuggestion =确保应用程序具有所需的隐私设置。,NSLocalizedDescription =必需的传感器失败。}


ios video tracking arkit
2个回答
3
投票

更新

解决方案是在手机设置中设置罗盘校准。 Credit to this answer.

转至设置>隐私>位置服务>系统服务,然后将指南针校准设置为开。

如何防止崩溃

在您的班级顶部声明您的配置,例如:

var configuration = ARWorldTrackingConfiguration()并确保在viewWillAppear方法中设置并添加配置。

然后添加此方法来处理错误。

func session(_ session: ARSession, didFailWithError error: Error) {
    // Present an error message to the user
    print("Session failed. Changing worldAlignment property.")
    print(error.localizedDescription)

    if let arError = error as? ARError {
        switch arError.errorCode {
        case 102:
            configuration.worldAlignment = .gravity
            restartSessionWithoutDelete()
        default:
            restartSessionWithoutDelete()
        }
    }
}

它只是处理你注意到的错误。

接下来,添加此函数以使用新的配置worldAlignment重置会话:

func restartSessionWithoutDelete() {
    // Restart session with a different worldAlignment - prevents bug from crashing app
    self.sceneView.session.pause()

    self.sceneView.session.run(configuration, options: [
        .resetTracking,
        .removeExistingAnchors])
}

希望它有所帮助,我也希望找到这个明显错误的实际修复。


2
投票

worldAlignment设置为gravityAndHeading需要启用位置服务:

  • 检查您的设备是否已启用位置服务。
  • 检查Info.plist是否设置了Privacy - Photo Library Additions Usage Description

如果指南针方向对您的应用至关重要,则应考虑引导用户启用位置服务并实施后备。

© www.soinside.com 2019 - 2024. All rights reserved.