NSUbiquitousKeyValueStore API 无法在 macOS Monterey 上运行
我的应用程序使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论