Trouble loading AR Reference Objects from URL

I am working on developing an AR app that will detect different networking devices used by my company. This app will be distributed among our company and potentially to our customers. I have created a working app that detects reference objects loaded into the assets catalog of xcode. What I am trying to do now is be able to load additional reference objects from local storage on a phone when new devices are scanned. I am trying to load from the url path to the folder I am saving all the new scans on but xcode keeps giving me an error message saying it cannot read the url path.


Here is the code I am trying to run:


let configuration = ARWorldTrackingConfiguration()


configuration.detectionObjects = ARReferenceObject.referenceObjects(inGroupNamed: "Devices", bundle: Bundle.main)!

let urlPath = "/private/var/mobile/Containers/Data/Application/"

let completeURL = URL(fileURLWithPath: urlPath)

do {

let newReferenceObject = try ARReferenceObject(archiveURL: completeURL)

configuration.detectionObjects.insert(newReferenceObject)

} catch {

fatalError("Failed to create reference object from archiveURL.")

}

sceneView.session.run(configuration)




And this is the error message I keep getting:


2020-02-19 13:08:02.112476-0700 icfgar[11769:2529945] [General] Unable to read archive at path: /private/var/mobile/Containers/Data/Application.

Fatal error: Failed to create reference object from archiveURL.: file /Users/taylorjohnson/Desktop/icfgar/icfgar/ViewController.swift, line 73



Any help would be appreciated.

Just taking a guess here, but I am pretty sure that your app cannot access anything at the path "/private/var/mobile/Containers/Data/Application/"


Since iOS apps live within their own container, they do not have access to the device's file system (and the path you provided also doesn't seem like a full path to an image or 3D object scan). Ideally, you would either want to bundle your 3D reference objects into the app itself (they don't have to live in the assets catalog, they could live in an oragnized folder amongst your code), and programatically instantiate the object, or, for more dynamic control, have AR reference objects live on a server somewhere, and have the app download the objects so their device always has the latest saved into storage.
You seem like you're creating the ARReferenceObject properly, it just doesn't seem like you have the right path to the objects. I would suggest either saving an object locally amongst your code, and calling it by doing something like;

let completeURL = Bundle.main.url(forResource: "fileName", withExtension: "arobject")


If that approach works, you could expand to storing a multitude of AR objects in a folder, run through the contents of that folder, and create each ARReferenceObject to add to the configuration. Or, you could also take the approach of saving the arobjects on a server and having your app download and save them locally, then build the ARReferenceObjects from the path saved locally upon download.

Trouble loading AR Reference Objects from URL
 
 
Q