1
votes

I have been making an app that contains several targets cooperate with each other as an app group.

Problems came when I began to make it Sandboxed:

  • the app stores URLs in the Core Data, and one target does the saving and another the reading
  • now the bookmark created by a target cannot be solved by the other

I know document-scoped bookmarks could be shared among apps. But it seems that they need to be stored into another "wrapper" document.

Is there a good way to store document-scoped bookmarks in Core Data and share them among different targets?

1

1 Answers

0
votes

In the case of multiple targets, make sure you are sharing the Core data model using a common App Groups container?All the targets should be looking at the same container? Make sure also that the targets are members of the same Core data model. If not, the different targets can't use the same model. See the identity inspector inside the core data attributes area and make sure your targets are ticked?

Store security-scoped bookmarks from a URL using:

(NSData *) bookmarkDataWithOptions: (NSURLBookmarkCreationOptions) options 
    includingResourceValuesForKeys: (NSArray<NSURLResourceKey> *) keys 
                     relativeToURL: (NSURL *) relativeURL 
                             error: (NSError * _Nullable *) error;

Save NSData that results, in core data, as Binary Data datatype.

Resolve the bookmark using:

(instancetype) URLByResolvingBookmarkData: (NSData *)bookmarkData 
                                  options: (NSURLBookmarkResolutionOptions) options
                            relativeToURL: (NSURL *) relativeURL 
                      bookmarkDataIsStale: (BOOL *) isStale
                                    error: (NSError * _Nullable *) error; 

This returns a URL.

Have a look at WWDC 15 session 234 and the accompanying sample code in relation to security-scoped bookmarks.

Hope this helps..