File Provider: Sandbox extension creation failed

I have a main macOS app that communicates with a file provider extension. I want to open a file from the main app that resides in the file provider. It works but I get a sandboxing error in the console:

[general] Sandbox extension data required immediately for flavor public.file-url, but failed to obtain.

[sandbox] Sandbox extension creation failed: client lacks entitlements? for path: [/Users/x/Library/CloudStorage/centea/readwrite folder] [/Users/x/Library/CloudStorage/centea/readwrite folder]

I am using getUserVisibleURL from NSFileProviderManager

manager.getUserVisibleURL(for:NSFileProviderItemIdentifier(identifier), completionHandler: { url, error in
    guard let url = url else { return }
    NSWorkspace.shared.activateFileViewerSelecting([url])
})

I set com.apple.security.files.user-selected.read-only to true but it doesn't help. Are there other custom entitlements (maybe containing "public.file-url"?), am I opening the file in a wrong way or what am I missing?

Answered by centea in 678652022

I was missing this: https://developer.apple.com/documentation/foundation/url/1779698-startaccessingsecurityscopedreso/

      url.startAccessingSecurityScopedResource()
      NSWorkspace.shared.activateFileViewerSelecting([url])
      url.stopAccessingSecurityScopedResource()
Accepted Answer

I was missing this: https://developer.apple.com/documentation/foundation/url/1779698-startaccessingsecurityscopedreso/

      url.startAccessingSecurityScopedResource()
      NSWorkspace.shared.activateFileViewerSelecting([url])
      url.stopAccessingSecurityScopedResource()
File Provider: Sandbox extension creation failed
 
 
Q