98

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?

11
  • 8
    i am having with this same issue in my app Jul 12, 2016 at 11:36
  • @PravinKamble I got this error, but I can access everything (user defaults's appgroup).
    – Klevison
    Jul 12, 2016 at 13:37
  • 1
    changing deployment target on 9.3 it will perfectly runs on the device but it won't work with iOS 10 i will be looking for solution i will be post here as soon as find solution Jul 13, 2016 at 5:21
  • @PravinKamble have you created your project using Xcode 8 beta 2?
    – Klevison
    Jul 13, 2016 at 14:18
  • I get the same thing using shared defaults with XCode 8 beta 4.
    – Gruntcakes
    Aug 3, 2016 at 15:49

12 Answers 12

92

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

3
  • 1
    I tried to create an app group that starts with the team ID but it forces it to start with 'group'. So - are the two not supposed to match???
    – SAHM
    Jun 1, 2017 at 2:37
  • 3
    I'm seeing this log messages on High Sierra. Prepending the team ID does not silence the warning for me. Is Apple intending to fix this?
    – mschmidt
    Jan 2, 2018 at 21:26
  • 2
    Sorry, Can you please elaborate? "prepend your team ID" to what? Sep 7, 2019 at 17:07
20

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

6
  • "simply select the group that was just created in the main app target" => What to do when it didn't appear ?? Jul 4, 2017 at 18:10
  • enable & select same group in extension too! Jul 4, 2017 at 18:12
  • I repeat, how to select same group if the selection is empty in the extension ??? Jul 4, 2017 at 18:22
  • When you toggle/enable groups under Compatibility section, then it auto show list of groups, if not showing then check the Team (Signing developer account), Team also need same! Set team and toggle groups again! Jul 4, 2017 at 18:27
  • it still don't work... however with iOS project it works. I'v created a thread : stackoverflow.com/questions/44914304/… Jul 5, 2017 at 9:52
6

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

1
  • Thank's so much. I've tried all things before. Jul 5, 2021 at 17:14
4

Also had same issue with my macOS app.

Solved it by: Reboot the device!

https://stackoverflow.com/a/39876271

1
4

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

3

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.

1

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.

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.

0
0

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

0

By default, if you are using the Settings.Bundle/Root.plist for displaying and editing your app preferences via Apple Settings App, it uses the UserDefaults.standard dictionary.

So if you are using App-Groups and you want to share this defaults / settings within your apps and extension, you need to change the container of your settings.

Step 1: Open your Settings.Bundle -> Root.plist

Open Settings.Bundle -> Root.plist

Step2: Add the key ApplicationGroupContainerIdentifier and as value set your App-Group-Id, defined in your Signing & Capabilities: Looks like group.xx.yy

Add Key-Value pair for ApplicationGroupContainerIdentifier

After you have implemented this step, the default container for your App-Settings will now switch from UserDefaults.standard (your apps Path) to the Shared Path.

0

Set by example

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.xxx.xxx"];
[userDefaults setValue:@"value" forKey:@"key"]
[userDefaults synchronize]; // return maybe false, but it doesn't matter

Get by

NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
[userDefaults addSuiteNamed:@"group.com.xxx.xxx"];
NSString *value = [useDefaults valueForKey:@"key"];

Although the same error will still be printed when setting, the value is indeed set and can be read correctly. But I don't know why this is happening, it's just the result of various attempts.

-4

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

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

This code reset default userDefault.

Actually,the correct code is:

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

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

0
-10

Change from

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

to

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

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

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

6
  • 2
    Are we supposed to use "nnnnnnnnnn.group.com.xxx.xxx" for writing in the main app as well, or just use the team ID in the extension? For me, adding the team id appears to pull a blank UserDeaults without any of the data I saved to "group.com.xxx.xxx" in my app. Really hoping there is a fix to this, as it's blocking my iOS 10 update. Sep 8, 2016 at 18:48
  • 2
    Data still doesn't sync. Error does go away.
    – Jeet
    Sep 13, 2016 at 15:03
  • 3
    currently it seems this error doesn't affect app. But if adding Team id, the error is missing but the data can't fetch.
    – scorpiozj
    Sep 18, 2016 at 13:25
  • 4
    This is not a good answers. You would put any thing else and skip the error as help as you change the key.
    – kokluch
    Oct 21, 2016 at 8:38
  • Not working in my case, error disappears but data is not fetching
    – TibiaZ
    Jan 7, 2019 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.