Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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." 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.}


like image 663
Caoyang Jiang Avatar asked Aug 12 '17 22:08

Caoyang Jiang


2 Answers

Update

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.

How to prevent Crashing

Declare your config at the top of your class e.g:

var configuration = ARWorldTrackingConfiguration() and make sure you setup and add your config in the viewWillAppear method.

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:

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.

like image 83
Josh Avatar answered Sep 25 '22 10:09

Josh


Setting worldAlignment to gravityAndHeading needs the location service to be enabled:

  • check if your device has location service turned on.
  • Check if Info.plist has set 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.

like image 34
macrozone Avatar answered Sep 24 '22 10:09

macrozone