在Finder Sync Extension中将安全范围书签与App Group UserDefaults一起使用 [英] Using Security Scoped Bookmark in Finder Sync Extension with App Group UserDefaults

查看:166
本文介绍了在Finder Sync Extension中将安全范围书签与App Group UserDefaults一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的finder同步扩展程序中解决安全范围书签"时,出现以下错误.

I am getting following error while resolving Security Scoped Bookmark in my finder sync extension.

Error Domain = NSCocoaErrorDomain代码= 259无法打开文件,因为文件格式不正确."

Error Domain=NSCocoaErrorDomain Code=259 "The File couldn't be opened because it isn't in the correct format."

以及可能的相关日志记录:

and also possibly the related logging:

无法读取CFPrefsPlistSource中的值<0x6080000ee380>(域:MyAppGroupName,用户:kCFPreferencesAnyUser,ByHost:是,容器:(空)):仅将kCFPreferencesAnyUser用于容器,与cfprefsd分开

Failed to read values in CFPrefsPlistSource<0x6080000ee380> (Domain: MyAppGroupName, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null)): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd

我正在使用以下代码在Container App中创建安全范围"书签:

I am using following code to create Security Scoped bookmark in Container App:

NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.mycomp.xyz"];
NSURL * theSelectedFolder = ....selected folder from NSOpenPanel....
NSData *bookmarkData = [theSelectedFolder bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];

[sharedDefaults setObject:bookmarkData forKey:@"BookmarkData"];
[sharedDefaults synchronize];

在Finder同步扩展程序中,我正在使用以下代码:

In Finder Sync Extension, I am using following code:

NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.mycomp.xyz"];
NSData *bookmarkData = [sharedDefaults objectForKey:@"BookmarkData"];
BOOL bookmarkDataIsStale;
NSError *err;
NSURL *userSelectedUrl = [NSURL URLByResolvingBookmarkData:bookmarkData options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&bookmarkDataIsStale error:&err];

,并且我还添加了此权利密钥: Finder Sync Extension和Container应用中的com.apple.security.files.bookmarks.app-scope.

and i have also added this entitlement key: com.apple.security.files.bookmarks.app-scope in both Finder Sync Extension as well as Container app.

我是可可编程的新手,却找不到运气好的问题.

I am new to cocoa programming and not being able to find any luck finder the problem.

我做错了什么?有人可以帮我吗?

What am I doing wrong? Can anyone help me out here?

推荐答案

我收到了Apple Developer技术支持的回复.发表在下面:

I received a response from Apple Developer Technical support. Posted below:

跟进:701518883

Follow-up: 701518883

我对此进行了更多研究,所以让我在这里重新开始对话:

I dug into this some more, so let me restart the conversation here:

我需要在主Mac App及其Mac OS之间共享沙盒安全书签 FinderSync扩展程序.

I need to share Sandbox Security Bookmarks between my main Mac App and its FinderSync extension.

此处的根本问题是,应用范围,安全范围的书签仅在创建它的应用中有效.剩下两个选择:

The underlying issue here is that an app scoped, security scoped bookmark is ONLY valid within the app that created it. That leaves you with two options:

  1. 如果两个应用程序组件都同时运行,那么您可以将当前URL发送到另一个组件,后者可以创建并保存自己的应用程序范围,安全范围的书签.

  1. If both app components are running at the same time, then you can send the current URL to the other component, which can then create and save its own app scoped, security scoped bookmark.

如果这行不通,则另一个选择是创建文档范围的,安全范围的书签.

If that won’t work, then the other option is to create a document scoped, security scoped bookmark instead.

这篇关于在Finder Sync Extension中将安全范围书签与App Group UserDefaults一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆