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:
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?
答案 0 :(得分:0)
对于多个目标,请确保使用通用应用程序组容器共享Core数据模型?所有目标应该在同一个容器中查看?还要确保目标是同一Core数据模型的成员。如果不是,则不同的目标不能使用相同的模型。查看核心数据属性区域内的身份检查器,确保勾选目标?
使用以下方式从URL存储安全范围的书签:
(NSData *) bookmarkDataWithOptions: (NSURLBookmarkCreationOptions) options
includingResourceValuesForKeys: (NSArray<NSURLResourceKey> *) keys
relativeToURL: (NSURL *) relativeURL
error: (NSError * _Nullable *) error;
将NSData
保存为核心数据中的Binary Data
数据类型。
使用以下方法解析书签:
(instancetype) URLByResolvingBookmarkData: (NSData *)bookmarkData
options: (NSURLBookmarkResolutionOptions) options
relativeToURL: (NSURL *) relativeURL
bookmarkDataIsStale: (BOOL *) isStale
error: (NSError * _Nullable *) error;
这会返回一个网址。
查看WWDC 15 session 234以及与安全范围书签相关的示例代码。
希望这会有所帮助..