I'm kind of stuck here. I changed code so here is the new approach.
- I create bookmark in Application Sandboxed Document folder:
let url = try! await NSFileProviderManager(for: SREG.context.domain)?.getUserVisibleURL(for: .rootContainer)
let bookmarkData = try! url!.bookmarkData(options: [.suitableForBookmarkFile], includingResourceValuesForKeys: nil, relativeTo: nil)
let dirURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let bookmarkURL = dirURL.appendingPathComponent("RootFolderLink")
try URL.writeBookmarkData(bookmarkData, to: bookmarkURL)
- Then at later point when I try to programmatically open the bookmark:
let dirURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let bookmarkURL = dirURL.appendingPathComponent("RootFolderLink")
let bookmarkData = try bookmarkURL.bookmarkData(options: .withSecurityScope)
let mountURL = try URL(resolvingBookmarkData: bdata, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale)
let res = mountURL?.startAccessingSecurityScopedResource() ?? false
if res {
NSWorkspace.shared.open(mountURL!)
mountURL?.stopAccessingSecurityScopedResource()
}
The Finder does indeed open the FileProvider root folder. However, after quitting the app and trying to open the folder again, I get error message:
Important note is that I still have the part with NSOpenPanel where user chooses location where to store bookmark (ie in his Home folder). And only in session where this dialog is shown, opening bookmark will work programmatically.
How was app able to open the bookmark link in the same session when it was created, but after app relaunch it refuses to open the link? What can I do to fix this issue? Could it have something to do with signing? This is Xcode debug run.