Context I'm writing an app that allows a user to select folders, and then scan them for files. The folder could be on the user's machine, iCloud or external storage. The app persists the details of these files and source folders to a document, so the user can access the files and re-scan the source folders in the future. The App is being written using the SwiftUI framework for MacOS and the iPad.
Problems Given this is a Sandboxed app I need to create security-scoped bookmarks to be able to access the folders that have been persisted to the document. I have two questions:
- How can I create a document-scoped bookmark, when using ReferenceFileDocument protocol. I need the document's URL, but I will never have access to this. I want to achieve something like this when implementing the fileWrapper function (bare bones example):
func fileWrapper(snapshot: MyDocument, configuration: WriteConfiguration) throws -> FileWrapper { : // Other code : let bookmarkDataToPersist = snapshort.someFileURL.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: documentURL) : // Other code to add bookmarkDataToPersist to fileWrapper }
- Ideally the user would be able to:
- connect an external drive to their Mac
- select a folder on that drive
- save the document, which would persist a bookmark to that folder's URL
- send the document to an iPad (via email or iCloud drive)
- open the document using the iPad version of the App
- connect the external bookmark to the iPad
- re-scan the folder which was book marked in the document from the folder
But given the problem in 1) and the fact that document-bookmarks cannot point to folders, is there a way?
Any ideas or suggestions would be very welcome.