Answering my own question to close this out:
FWIW, as Quinn points out, yes, startAccessingSecurityScopedResource() is critical. Preserving access across app restarts and device reboots took some experimentation to find the right incantation of keys baked into the bookmark. The following is what I am using (some of these are particular things I need, but the security and permissions-related ones are critical):
extension URL {
/// Get a bookmark to a file in a folder the user has granted access to, which will
/// be usable across a device reboot.
func rebootSafeFolderBookmark() throws -> Data {
try self.bookmarkData(includingResourceValuesForKeys: [.fileSecurityKey, .volumeSupportsExtendedSecurityKey, .contentModificationDateKey, .isDirectoryKey, .fileResourceIdentifierKey, .isUbiquitousItemKey, .ubiquitousItemContainerDisplayNameKey, .fileProtectionKey, .ubiquitousSharedItemCurrentUserPermissionsKey, .parentDirectoryURLKey, .addedToDirectoryDateKey])
}
/// Get a bookmark to a file in a folder the user has granted access to, which will
/// be usable across a device reboot.
func rebootSafeBookmark() throws -> Data {
try self.bookmarkData(includingResourceValuesForKeys: [.fileSecurityKey, .volumeSupportsExtendedSecurityKey, .contentModificationDateKey, .isDirectoryKey, .fileResourceIdentifierKey, .ubiquitousSharedItemCurrentUserPermissionsKey, .isUbiquitousItemKey, .fileProtectionKey, .addedToDirectoryDateKey])
}
}
Topic:
App & System Services
SubTopic:
Core OS
Tags: