MacOS internal sandbox error for <StopAccessing>

428 Views Asked by At

I'm building a MacOS app that lets users edit a file. To access a file, I use a security scoped bookmark like so:

do {
            self.securityScopedBookmark = try asset?.url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
        } catch {
            print("failed bookmark. error info: \(error)")
        }

When the user is done and the NSDocument is deinitialized, I stop accessing the bookmark like so:

   deinit {
        if let securityScopedBookmark = self.securityScopedBookmark {
            do {
                var isStale: Bool = false
                
                let url = try URL.init(resolvingBookmarkData: securityScopedBookmark, options: [.withoutUI, .withSecurityScope], relativeTo: nil, bookmarkDataIsStale: &isStale)
                url.stopAccessingSecurityScopedResource()
            } catch let error as NSError {
                print("Bookmark Access Fails: \(error.description)")
            }
        }
}

However when trying to call .stopAccessingSecurityScopedBookmark(), I get a couple log errors.

 [scoped] handle 0: sandbox_extension_release error [22: Invalid argument]
 [scoped] <0x60000202e400 file:///Users/user/Desktop/file.mp4>: internal sandbox error for <StopAccessing>

I'm not sure if these errors will create a problem or not. Everything seems to be working either way, but I'm worried that in deployment there will be problems.

I am using the following security entitlement keys:

   <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
   <key>com.apple.security.files.bookmarks.document-scope</key>
    <true/>
0

There are 0 best solutions below