[英]Apple iOS ARKit: “A sensor failed to deliver the required input” error and stops working
I am developing an application that uses both ARKit and hardware video decoder. 我正在开发一个同时使用ARKit和硬件视频解码器的应用程序。 As soon as the decoder start to decode, the following error message appears in console and prevent tracking from working properly.
一旦解码器开始解码,控制台中就会出现以下错误消息,并阻止跟踪正常工作。
Occasionally, this error do not show up and the app works normally. 有时,此错误不会显示,应用程序正常工作。 After some debugging, I found out this error only happens at the "beginning" (shortly after launching the app).
经过一些调试后,我发现这个错误只发生在“开始”(启动应用程序后不久)。 Once it passes that point, it works fine for the rest of the time.
一旦它通过该点,它在其余时间工作正常。
Does anyone know what the problem is or how to go around it? 有谁知道问题是什么或如何绕过它?
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] [Session] Session did fail with error: Error Domain=com.apple.arkit.error Code=102 "Required sensor failed."
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=A sensor failed to deliver the required input., NSUnderlyingError=0x1c4c51280 {Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo={NSLocalizedDescription=Cannot Complete Action, NSLocalizedRecoverySuggestion=Try again later.}}, NSLocalizedRecoverySuggestion=Make sure that the application has the required privacy settings., NSLocalizedDescription=Required sensor failed.}
UserInfo = {NSLocalizedFailureReason =传感器未能提供所需的输入。,NSUnderlyingError = 0x1c4c51280 {错误域= AVFoundationErrorDomain代码= -11819“无法完成操作”UserInfo = {NSLocalizedDescription =无法完成操作,NSLocalizedRecoverySuggestion =稍后再试。}}, NSLocalizedRecoverySuggestion =确保应用程序具有所需的隐私设置。,NSLocalizedDescription =必需的传感器失败。}
The solution is to do with compass calibration being set in the phone settings. 解决方案是在手机设置中设置罗盘校准。 Credit to this answer.
相信这个答案。
Go to Settings > Privacy > Location Services > System Services, and set Compass Calibration to ON.
转至设置>隐私>位置服务>系统服务,然后将指南针校准设置为开。
Declare your config at the top of your class eg: 在您的班级顶部声明您的配置,例如:
var configuration = ARWorldTrackingConfiguration()
and make sure you setup and add your config in the viewWillAppear
method. var configuration = ARWorldTrackingConfiguration()
并确保在viewWillAppear
方法中设置并添加配置。
Then add this method to handle the error. 然后添加此方法来处理错误。
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()
}
}
}
It just handles the error that you've noticed. 它只是处理你注意到的错误。
Next, add this function to reset the session with a new config worldAlignment: 接下来,添加此函数以使用新的配置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])
}
Hope it helps, and I also hope to find an actual fix to this apparent bug. 希望它有所帮助,我也希望找到这个明显错误的实际修复。
Setting worldAlignment
to gravityAndHeading
needs the location service to be enabled: 将
worldAlignment
设置为gravityAndHeading
需要启用位置服务:
Privacy - Photo Library Additions Usage Description
Privacy - Photo Library Additions Usage Description
If the compass orientation is crucial for your app, you should consider to guide the user to do turn the location service on and implement a fallback. 如果指南针方向对您的应用至关重要,则应考虑引导用户启用位置服务并实施后备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.