Swift ARKit How do you fully kill an ARSession?

北慕城南 提交于 2020-01-14 10:23:11

问题


I have an ARSCNView running an ARSession. You can pause the session with session.pause() sure, but that still in effect, leaves the session running. I have tried deallocating the ARSCNView by removing it from its superview. The ARSCNView indeed deallocates but the ARSession is still running afterwards!! You can't assign nil to ARSession either. I can see the ARSessionDelegate's

func session(_ session: ARSession, didUpdate frame: ARFrame) 

is still being called!

How do you completely wipe the slate clean with ARKit once you have finished with it?

Is it even possible?


回答1:


Officially, right now, you can't.

However, there is a work-around: you make the ARSCNView disposable.

On leaving AR, first pause the ARSession. Then deallocate the entire ARSCNView hierarchy & set ARSCNView to nil for good measure. Rebuild the entire ARSCNView hierarchy and start a new session whenever you need to go back to AR.

var ARview: ARSCNView?

func punchTheClown() {

    ARView?.session.pause()
    ARView?.removeFromSuperview()
    ARView = nil

}

Other non-AR areas of your app would typically be in a separate view hierarchy at the same sibling level as your ARSCNView. I look forward to Apple providing an actual stopSession() function, so we can all stop having to punchTheClown in the meantime.




回答2:


From the docs

While paused, the session doesn't track device motion or capture scene imagery, nor does it coordinate with its delegate object or update any associated ARSCNView or ARSKView object

If it isn’t causing issues, better be left alone. As far as I know. This works like a video player. You can Pause and resume it anytime

Source here: .RunOptions ARKit Docs



来源:https://stackoverflow.com/questions/52769317/swift-arkit-how-do-you-fully-kill-an-arsession

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!