I am working on an iOS shopping app that has the AR feature. Users can preview the products in AR using the iOS Quicklook. AR models are the usdz files.
Due to app/design requirements, I had to add custom views on Quicklook screen. Users should be able to select the color in AR Quicklook screen so I've created a new viewcontroller derived from QLPreviewController and added some UI components (collectionview, buttons, etc). I have different models for each color so when the user selects color then App should load a different model (usdz file). Here is the code snippet.
class ARViewController: QLPreviewController {
override func viewDidLoad() {
// add UI elements here (collectionview, buttons, ..)
}
}
Everything is okay till now. I can open the AR Quicklook and can place the object first time.
The problems are
- when I change the product by selecting the collectionview cell, Quicklook automatically switched to "Object" view even previous model is in AR screen (camera)
- AR screen (camera) becomes disable state. I can't see new models in AR screen anymore. I have to close the AR screen to reactive the AR mode. or sometimes I have to restart the app (just dismissing the QLPreviewController is not working for next AR view).
Here is the QLPreviewDataSource code
class ViewController: QLPreviewControllerDataSource {
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1 // I did try to update this number but did not worked
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
let productUrl = getProductUrl()
return productUrl as QLPreviewItem // I did try to pass ARQuickLookPreviewItem but same issue
}
}
When the user taps on the collectionViewCell in Quiclook, I just updated the AR model name and called QLPreviewController's reloadData function.
self.reloadData() // Also tried self.refreshCurrentPreviewItem() but same issue
Any help would be greatly appreciated. Thanks!