There is a good question and answer here about dynamically changing text of an entity in a Reality Composer scene. Is there a way to do the same but show it in a QLPreviewController rather than an ARView?
Here is code for loading a previewItem (from a URL) into the QLPreviewController. So I would like to dynamically change the text in the file before returning the preview item to display. Assume I am using a .rcproject that has a bubble text, for example.
class ARQLViewController: UIViewController,
QLPreviewControllerDataSource,
QLPreviewControllerDelegate {
var allowsContentScaling = true
var webViewModel: WebViewModel
init(webViewModelReceived: WebViewModel) {
webViewModel = webViewModelReceived
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidAppear(_ animated: Bool) {
setupOnAppear()
}
func setupOnAppear() {
let previewController = QLPreviewController()
previewController.dataSource = self
previewController.delegate = self
present(previewController, animated: true, completion: nil)
}
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController,
previewItemAt index: Int) -> QLPreviewItem {
let url = webViewModel.afUrlForAR
let previewItem = ARQuickLookPreviewItem(fileAt: url!)
previewItem.allowsContentScaling = allowsContentScaling
return previewItem
}
}