NSUbiquitousKeyValueStore API 无法在 macOS Monterey 上运行

发布于 2025-01-15 15:15:44 字数 1104 浏览 2 评论 0原文

我的应用程序使用 iCloud 键值存储 Objective-C api,如下所示:

NSUbiquitousKeyValueStore* iCloudStorage = [NSUbiquitousKeyValueStore defaultStore];
[iCloudStorage synchronize];

[iCloudStorage setString:@"Test" forKey:@"TestStringKey"];
[iCloudStorage synchronize];

NSString* value = [iCloudStorage stringForKey:@"TestStringKey"];

要使用此 api,我将以下权利添加到权利文件中:

<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>

另外,我在developer.apple.com 上的证书、ID 和配置文件中启用了 iCloud 支持对于我的应用程序标识符,因此它看起来如 iCloud 键值存储文档中所述。问题是,这段代码在 Monterey 之前的所有 MacOS 版本上都可以正常工作,但该代码在 Monterey 版本上不起作用 - 无法保存字符串或从存储中检索它,并且在日志中我看到以下消息:

2022-03-15 17:41:17.119843+0300 [Connection] Unable to find entitlement for KVS store
2022-03-15 17:41:17.119888+0300 [Connection] Trying to initialize NSUbiquitousKeyValueStore without a store identifier. Please specify a store identifier in your entitlements or initializer.

在重新阅读此 api 的文档并确保我已按照此处所述设置了所有内容后,我没有找到问题的解决方案,因此我寻求帮助。

My app uses iCloud key-value storage objective-c api as follows:

NSUbiquitousKeyValueStore* iCloudStorage = [NSUbiquitousKeyValueStore defaultStore];
[iCloudStorage synchronize];

[iCloudStorage setString:@"Test" forKey:@"TestStringKey"];
[iCloudStorage synchronize];

NSString* value = [iCloudStorage stringForKey:@"TestStringKey"];

To use this api i add the following entitlement to the entitlements file:

<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>

Also, I've enabled iCloud support in Certificates, IDs, and Profiles on developer.apple.com for my app identifier, so it looks like as described in the iCloud Key-Value Storage documentation. The problem is that this code works without problems on all MacOS versions before Monterey, but the code does not work on the Monterey version - it is impossible to save the string or retrieve it from the storage and in the logs I see the following messages:

2022-03-15 17:41:17.119843+0300 [Connection] Unable to find entitlement for KVS store
2022-03-15 17:41:17.119888+0300 [Connection] Trying to initialize NSUbiquitousKeyValueStore without a store identifier. Please specify a store identifier in your entitlements or initializer.

After re-reading the documentation for this api and making sure that I have everything set up as described there, I did not find a solution to the problem, so I ask for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文