RealUglyDuck
RealUglyDuck

Reputation: 377

How to run two separate ARKit experiences in one iOS app

I have a problem with running two ARKit experiences in one app. I have main menu View Controller which runs either of the experiences. It looks something like that:

Both experiences are independent and they don't need to pass any data between each other. Unfortunately when I dismiss ARVC1 or ARVC2 and run the second one, somehow I have traces of the previous ARSession (still frame from previous session is flashing once for a while). Can I reset completely ARSession somehow? It seems that it stays somewhere in the background. I've tried to pause the session when I dismiss any of the View Controllers but it didn't help.

The same happens if I open ARVC1 and press the button to show statistics:

arView.debugOptions = [.showStatistics]

After dismissing ARVC1 and opening it again it still shows statistics so it's running somewhere in the background.

Upvotes: 2

Views: 1006

Answers (1)

RealUglyDuck
RealUglyDuck

Reputation: 377

I found the solution to my problem:

After opening and closing ARVC1 and quickly opening ARVC2 I was experiencing flickering of the previous ARSession in current ARSession. To solve this I create ARView in my MainVC and I pass the reference to it to destination controller, where I set up the arView constraints programmatically. To avoid passing the ARAnchors I reset configuration with options in viewDidLoad:

arView.session.run(configuration, options: [.resetTracking,.removeExistingAnchors,.stopTrackedRaycasts])

It helped as well with UINavigationController transition (made it smoother) because ARSession is configured before the View is presented and it eliminates the black flash that occurs at the moment when you run new ARConfiguration with ARSession.

It also eliminates the console error (below) that I was experiencing while quickly closing and opening ViewController containing ARView which sometimes was crashing the app:

[Session] Session (0x160879b40): 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=0x283f959b0 {Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x283efc8a0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}}, NSLocalizedRecoverySuggestion=Make sure that the application has the required privacy settings., NSLocalizedDescription=Required sensor failed.} 2020-01-09 16:20:38.600835+0000 App[573:231750] [Technique] World tracking performance is being affected by resource constraints [3] 2020-01-09 16:20:38.600977+0000 App[573:231750] [Technique] VIO error callback: 8506.590769, 3, Frame time stamps are either out of order or repeating

Upvotes: 1

Related Questions