Resolve bookmark created in iOS app in Share Extension

I create a URL bookmark with `URL.bookmarkData(options: [], includingResourceValuesForKeys: [.localizedNameKey])` and resolve it with `NSURL(resolvingBookmarkData: bookmarkData, options: [], relativeTo: nil, bookmarkDataIsStale: nil) as URL`. This works fine within my main app, but when sharing the bookmarkData via an App Group with my Share Extension, it gives the error "The file couldn't be opened because you don't have permission to view it.". Is there any way I can do this?

Answered by Developer Tools Engineer in 620024022
Hi Nickkk! This is presumably failing because the app you shared to doesn't have access to the original app's sandbox. You can resolve this by specifying .withSecurityScope in your option set when creating the bookmark. The target application will be able to resolve the bookmark, and must call startAccessingSecurityScopedResource() and stopAccessingSecurityScopedResource() when it needs to access the resource to which the bookmark refers. For more information, see:

https://developer.apple.com/documentation/foundation/nsurl/bookmarkcreationoptions/1413824-withsecurityscope
https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso
https://developer.apple.com/documentation/foundation/nsurl/1413736-stopaccessingsecurityscopedresou
Accepted Answer
Hi Nickkk! This is presumably failing because the app you shared to doesn't have access to the original app's sandbox. You can resolve this by specifying .withSecurityScope in your option set when creating the bookmark. The target application will be able to resolve the bookmark, and must call startAccessingSecurityScopedResource() and stopAccessingSecurityScopedResource() when it needs to access the resource to which the bookmark refers. For more information, see:

https://developer.apple.com/documentation/foundation/nsurl/bookmarkcreationoptions/1413824-withsecurityscope
https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso
https://developer.apple.com/documentation/foundation/nsurl/1413736-stopaccessingsecurityscopedresou
Sorry, I didn't know that clicking on the checkmark would mark your answer as the correct one (it looks more like a badge to show that your account is verified, so I was wondering where the link would bring me). Is it possible to revert this action?
Anyway, what you suggest is exactly what I'm doing (except that I cannot use withSecurityScope since I'm on iOS), and it's not working.

Anyway, what you suggest is exactly what I'm doing (except that I cannot use withSecurityScope since I'm on iOS), and it's not working.

Hi, did you find a way to solve this issue? I have run into the same one yesterday.


Unfortunately no.
Resolve bookmark created in iOS app in Share Extension
 
 
Q