2

I am creating sandboxed macOS application. I obtain file url from NSOpenPanel, create bookmark data and save to data storage. Then I can successfully restore url from bookmark data and access file data from my app.

I also have another target with XPC Service in the project, I pass restored url to this target, but I have no access to file from this url when I try to read file from this XPC Service.

My base app and XPC Service target both have com.apple.security.files.bookmarks.app-scope com.apple.security.files.bookmarks.document-scope com.apple.security.files.user-selected.read-write

What should I do to have access to files from restored urls in XPC Service target? AND can I copy or delete file from XPC Service?

Base app

NSURL *url = [NSURL URLByResolvingBookmarkData:file.bookmarkData
                                       options:NSURLBookmarkResolutionWithSecurityScope
                                 relativeToURL:nil
                           bookmarkDataIsStale:nil
                                         error:nil];
[url startAccessingSecurityScopedResource];
...
[self.connection.remoteObjectProxy getDataFromURL:url
                                        withReply:aReply];

XPC Service

- (void)getDataFromURL:(NSURL *)anURL
             withReply:(void (^)(NSData *))aReply {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        aReply([NSData dataWithContentsOfURL:anURL]);
    });
}

[NSData dataWithContentsOfURL:anURL] is nil

Maksym Shulha
  • 125
  • 1
  • 1
  • 8

0 Answers0