2
votes

I got a project that involves a few USDZ files for the augmented reality features embedded in the app. While this works great, and we're really happy with how it performs, the built-in share button of the QLPreviewController is something that we'd like to remove. Subclassing the object doesn't have any effect, and trying to hide the rightBarButtonItem with the controller returned in delegate method still shows the button when a file is selected. The implementation of USDZ + QLPreviewController we're using is pretty basic. Is there a way around this issue?

func numberOfPreviewItems(in controller: QLPreviewController) -> Int {  
      return 1  
 }   


func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {  

     let url = Bundle.main.url(forResource: models[selectedObject], withExtension: "usdz")! controller.navigationItem.rirButtonItems = nil.   
// <- no effect return url as QLPreviewItem   

}  

 @IBAction func userDidSelectARExperience(_ sender: Any) {   
     let previewController = QLPreviewController()   
     previewController.dataSource = self   
     previewController.delegate = self   
     present(previewController, animated: true)   
}  
5
Apple shouldn't make it this difficult to hide a buttongrantespo

5 Answers

2
votes

My approach is to add the QLPreviewController as an subview.

container is an UIView in storyboard.

let preview = QLPreviewController()

preview.dataSource = self

preview.view.frame = CGRect(origin: CGPoint(x: 0, y: -45), size: CGSize(width: container.frame.size.width, height: container.frame.size.height+45) )

container.addSubview(preview.view)
preview.didMove(toParent: self)

The y offset of the frame's origin and size may vary. This will ensure the AR QuickLook view to be the same size as the UIView, and hide the buttons (unfortunately, all of them) at the same time.

2
votes

Instead of returning QLPreviewItem, use ARQuickLookPreviewItem which conforms to this protocol.

https://developer.apple.com/documentation/arkit/arquicklookpreviewitem

Then, assign a url that you would want to share (that will appear in share sheet) in canonicalWebPageURL property. By default, this property shares the file url (in this case, the USDZ file url). Doing so would not expose your file URL(s).

2
votes

This is the official answer from Apple. Use ARQuickLookPreviewItem instead of QLPreviewItem. And set its canonicalWebPageURL to a URL (can be any URL).

func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        guard let path = Bundle.main.path(forResource: "Experience", ofType: "usdz") else { fatalError("Couldn't find the supported input file.") }
        let url = URL(fileURLWithPath: path)
        if #available(iOS 13.0, *) {
            let item = ARQuickLookPreviewItem(fileAt: url)
            item.canonicalWebPageURL = URL(string: "http://www.google.com")
            return item
        } else { }
        return url as QLPreviewItem
    }

The version check is optional.

0
votes

TLDR: I don't think you can.

I haven't seen any of the WWDC session even mention this and I can't seem to find any supporting developer documentation. I'm pretty sure the point of the ARKit QLPreviewController is so you don't have to do any actual coding on the AR side. I can see the appeal for this and for customisation in general, however, I'd suggest instead looking at some of the other ARKit projects that Apple has released and attempting to re-create those from the ground up as opposed to stripping this apart.

Please advise if this changes as I'd like to do something similar, especially within Safari.

0
votes

I couldn't get to the share button at all to hide or disable it. Spent days to overcome this. I did rather unprofessional way of overcoming it. Subview QLPreviewController to a ViewController and subview a button or view on top of image view on top of share button and setting my company logo as image. It will be there all the time, even the top bar hides on full screen in AR mode. Not a clean solution. But works.