0
votes

Firstly I would like to say that I'm really beginner in IOS development and AR technology. I have developed sample projects about AR using Arkit. I have created vitrual 3D object and put the object somewhere in real position. But the life cycle of object is for only one session.

I mean that the object appear one session, When I re-open the application in the same location, as normally Its possition losed. I do not save the position of object. How to provide persistance in Arkit ? I have read some articles about it.

For providing persistance AR experiences, Which steps should I follow ? How do I combines AR and location services? Does anyone has any idea? Could you help me about it?

If the question is duplicate, I am really sorry.

Best Regards.

1

1 Answers

2
votes

Restoring an AR Session experience has become very simple in iOS 12 and ARKit2. Apple has provided World Map Persistence in ARKit2 that lets you persist almost everything about your AR session. You can save the ARKit world map and restore the mapping data later, even when the app is terminated so that users can return to the previous AR Session when they later re-open the app.

As explained in Apple Documents, you can:

Save a world map when your app becomes inactive, then restore it the next time your app launches in the same physical environment. You can use anchors from the resumed world map to place the same virtual content at the same positions from the saved session.

ARWorldMap conforms to the NSSecureCoding protocol, so you can convert a world map to or from a binary data representation using the NSKeyedArchiver and NSKeyedUnarchiver classes.

You convert world map to data and store it in a file, then you can load this file later on the next app launch and convert it back to ARWorldMap and set scene view configuration’s initial world map to the loaded world map:

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Retrieve the persisted world map, then simply set it in the configuration and run the session:

    let configuration = ARWorldTrackingConfiguration()
    configuration.initialWorldMap = worldMap

    sceneView.session.run(configuration)
} 

You can follow this tutorial for a complete working example.