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.}
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 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.
Setting worldAlignment
to gravityAndHeading
needs the location service to be enabled:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With