11

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


Caoyang Jiang
  • 141
  • 1
  • 5
  • Hello Caoyang Jiang, I found out, that if you just comment out the following line: "configuration.worldAlignment = .gravityAndHeading", everything is working correctly again. I know, its not a real solution, but the app in my case is running. (https://developer.apple.com/documentation/arkit/arconfiguration.worldalignment/2873776-gravityandheading) – Mr. T Aug 18 '17 at 07:43
  • If you use the following line: "configuration.worldAlignment = .gravityAndHeading". Then you could start a new session in: func session(_ session: ARSession, didFailWithError error: Error) {} with just "configuration.worldAlignment = .gravity" You can by now solve the issue and hope, that it will be solved it future releases. – Mr. T Aug 18 '17 at 07:56
  • Mr.T, I tried what you suggested. Unfortunately it does not solve my problem. The code still failed now and then with the same problem. On the iPhone screen, it shows "Required sensor failed. A sensor failed to deliver the required input. This is an unrecoverable error hat requires to quit the application." – Caoyang Jiang Aug 21 '17 at 22:44
  • Does your Device has at least an A9 chip? Edit: And what, if you just use .gravity at initial setup? – Mr. T Aug 23 '17 at 14:16
  • Mr.T, thanks the your helps. Yes, the iPhone I am using is iPhone SE and it is equipped with a A9 chip. I have tried all of the possible options. They don't seem to completely solve the problem. – Caoyang Jiang Sep 01 '17 at 18:06
  • Have you had any luck with this? – Hari Honor Oct 20 '17 at 13:45

2 Answers2

8

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.

Josh
  • 529
  • 6
  • 21
4

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.

macrozone
  • 850
  • 1
  • 7
  • 21