Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to read values in CFPrefsPlistSource iOS 10

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:

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

Anyone can help me?

like image 225
Klevison Avatar asked Jul 08 '16 21:07

Klevison


3 Answers

This is actually a spurious warning that was introduced in iOS 10 and 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]

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.

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

Also, Apple staff member CFM on the forums:

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).

like image 76
waltflanagan Avatar answered Nov 14 '22 02:11

waltflanagan


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

  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 UserDefaults in either your app or your extension, do not access UserDefaults.standard. Instead use UserDefaults(suiteName: "group.io.intrepid.myapp"). Note: The suite name is the name of your App Group container created in Step 4.

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

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

like image 22
Arfan Mirza Avatar answered Nov 14 '22 03:11

Arfan Mirza


Change you group name in Xcode entitlements from:

group.com.mycompany.myapp

To

group.MYTEAMID.com.mycompany.myapp

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

like image 9
Santiago Avatar answered Nov 14 '22 02:11

Santiago