无法读取 CFPrefsPlistSource iOS 10 中的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38275395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:39:53  来源:igfitidea点击:

Failed to read values in CFPrefsPlistSource iOS 10

iosxcodeios10ios-app-group

提问by Klevison

I've updated my Xcode 8 to beta 2 today and I'm trying to share data between App and Today Extension. I'm facing with this log warning:

我今天已将我的 Xcode 8 更新为 beta 2,并且我正在尝试在 App 和 Today Extension 之间共享数据。我正面临这个日志警告:

2016-07-08 18:00:24.732472 ProjetctX[941:42801] [User Defaults] Failed to read values in CFPrefsPlistSource<0x1700f1280> (Domain: group.x.p.t.o, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null)): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd

2016-07-08 18:00:24.732472 ProjetctX[941:42801] [用户默认值] 无法读取 CFPrefsPlistSource<0x1700f1280> 中的值(域:group.xpto,用户:kCFPreferencesAnyUser),容器:(ByHost:) : 将 kCFPreferencesAnyUser 与容器一起使用只允许用于系统容器,与 cfprefsd 分离

Anyone can help me?

任何人都可以帮助我吗?

采纳答案by waltflanagan

This is actually a spurious warning that was introduced in iOS 10 and macOS 10.12:

这实际上是在 iOS 10 和 macOS 10.12 中引入的虚假警告:

NSUserDefaults tip: in the current OSs there's a logged error "…with a container is only allowed for System Containers…".

This is spurious.

Trying to catch a particular failure mode, caught a normal operation case at the same time.

My successor on UserDefaults also has not figured out a way to make this less alarming without making the symptomatic case impossible to debug :/

https://twitter.com/Catfish_Man/status/784460565972332544[thread]

NSUserDefaults 提示:在当前的操作系统中,有一个记录的错误“......容器只允许用于系统容器......”。

这是虚假的。

试图捕捉特定的故障模式,同时捕捉到一个正常的操作案例。

我在 UserDefaults 上的继任者也没有想出一种方法来使这种情况不那么令人担忧,而不会使有症状的情况无法调试:/

https://twitter.com/Catfish_Man/status/784460565972332544[线程]

The advice of prepending your team ID will silence the warning, but will also create a new empty user defaults. This will result in any previously stored data being unreadable.

预先添加团队 ID 的建议将使警告静音,但也会创建一个新的空用户默认值。这将导致任何先前存储的数据无法读取。

For the time being, the solution is just to ignore it.

目前,解决办法就是忽略它。

Also, Apple staff member CFM on the forums:

此外,论坛上的Apple 工作人员 CFM :

The logged message is spurious unless you're doing very specific things that I don't think are possible without using private functions (it was added to catch misuse of those functions, but unfortunately also caught a normal usage case).

记录的消息是虚假的,除非您正在做非常具体的事情,我认为不使用私有函数是不可能的(添加它是为了捕获对这些函数的滥用,但不幸的是也捕获了正常的用例)。

回答by Arfan Mirza

Here's how to use NSUserDefaults with App Groups to pass data between your main app and your extension:

以下是如何使用 NSUserDefaults 和应用程序组在主应用程序和扩展程序之间传递数据:

  1. In your main app, select your project in the Project Navigator.

  2. Select your main app target and choose the Capabilities tab.

  3. Toggle the App Groups switch to ON. This will communicate with the Developer Portal in order to generate a set of entitlements.

  4. Create a new container. According to Apple, your container ID must start with "group", so a name such as "group.io.intrepid.myapp" is perfect.

  5. Select your extension target and repeat the process of enabling App Groups. Do not create a new App Group, simply select the group that was just created in the main app target.

  6. When reading or writing NSUserDefaults in either your app or your extension, do not access NSUserDefaults.standardUserDefaults(). Instead use NSUserDefaults(suiteName: "group.io.intrepid.myapp"). Note: The suite name is the name of your App Group container created in Step 4.

  1. 在您的主应用程序中,在 Project Navigator 中选择您的项目。

  2. 选择您的主要应用程序目标并选择功能选项卡。

  3. 将应用程序组切换到 ON。这将与 Developer Portal 通信以生成一组权利。

  4. 创建一个新容器。根据 Apple 的说法,您的容器 ID 必须以“group”开头,因此诸如“group.io.intrepid.myapp”之类的名称是完美的。

  5. 选择您的扩展目标并重复启用应用程序组的过程。不要创建新的应用程序组,只需选择刚刚在主应用程序目标中创建的组。

  6. 在您的应用程序或扩展程序中读取或写入 NSUserDefaults 时,请勿访问 NSUserDefaults.standardUserDefaults()。而是使用 NSUserDefaults(suiteName: "group.io.intrepid.myapp")。注意:套件名称是在步骤 4 中创建的应用程序组容器的名称。

Make sure, group enable and using same group id for both extension and app capability section!

确保为扩展程序和应用程序功能部分启用并使用相同的组 ID!

Credit goes to http://blog.intrepid.io/ios-app-extensions

幸得http://blog.intrepid.io/ios-app-extensions

回答by Jxtt

Also had same issue with my macOS app.

我的 macOS 应用程序也有同样的问题。

Solved it by: Reboot the device!

解决方法:重启设备!

https://stackoverflow.com/a/39876271

https://stackoverflow.com/a/39876271

回答by Emmanuel Sellier

The SuiteName (postfix) must not be the main Bundle ID.

SuiteName(后缀)不能是主要的 Bundle ID。

回答by Santiago

Change you group name in Xcode entitlements from:

从以下位置更改 Xcode 权利中的组名称:

group.com.mycompany.myapp

To

group.MYTEAMID.com.mycompany.myapp

ps: you can find your MYTEAMID in developer.apple.com membership

ps:您可以在 developer.apple.com 会员中找到您的 MYTEAMID

回答by Vitaly Baum

The solution for me was to not use the same identifier for the application Bundle Identifier and the part after "group.".

我的解决方案是不对应用程序捆绑标识符和“组”之后的部分使用相同的标识符。

Say, the app bundle id is "com.app.id", then group id as "group.com.app.id" is causing issues. After I change it to "group.com.app.id.something" it stops.

比如说,应用程序包 ID 是“com.app.id”,然后组 ID 为“group.com.app.id”会导致问题。在我将其更改为“group.com.app.id.something”后,它停止了。

回答by raz0r

Build with Xcode 8.1 Beta and you will see the same warning, but you will also get the value.

使用 Xcode 8.1 Beta 构建,您将看到相同的警告,但您也将获得值。

回答by Sagar D

I'm facing this same issue when I'm trying to use initWithSuiteName. Seems that this is a bug from Apple. The only solution / workaround I found is to reset all the settings of the device. Go to Settings -> General -> Reset -> Reset All Settings.

当我尝试使用 initWithSuiteName 时,我面临着同样的问题。似乎这是来自Apple的错误。我找到的唯一解决方案/解决方法是重置设备的所有设置。转到设置 -> 常规 -> 重置 -> 重置所有设置。

This doesn't erase any content on the iPhone, just erases all the settings. After resetting the setting, everything worked fine. Let me know if it helps you too.

这不会清除 iPhone 上的任何内容,只会清除所有设置。重置设置后,一切正常。如果它也对您有帮助,请告诉我。

回答by H u Y an g

if you suffer this problem when you try to save data to extension APP by using userDefault, maybe you had written this code:

如果您在尝试使用 将数据保存到扩展 APP 时遇到此问题userDefault,也许您已经编写了以下代码:

[[NSUserDefaults standardUserDefaults] initWithSuiteName:@"group.xxx.com"];

This code reset default userDefault.

此代码重置默认值userDefault

Actually,the correct code is:

实际上,正确的代码是:

[[NSUserDefaults alloc] initWithSuiteName:@"group.xxx.com"];

http://www.jianshu.com/p/e782104c3bc3

http://www.jianshu.com/p/e782104c3bc3

回答by Titan

Change from

更改自

[[NSUserDefaults alloc] initWithSuiteName:@"group.com.xxx.xxx"];

to

[[NSUserDefaults alloc] initWithSuiteName:@"nnnnnnnnnn.group.com.xxx.xxx"]; 

Where nnnnnnnnnis your team number, the one which you use to sign your code.

nnnnnnnnn你的团队号码在哪里,你用来签署代码的号码。

Tested under Xcode 8 GM and iOS 10 GM, and worked!

在 Xcode 8 GM 和 iOS 10 GM 下测试,并且有效!