0

I've had this running in the past for my other app (between a Today extension and the host app), however, for a brand new app created with Xcode 9.1 I see strange errors:

2017-12-25 17:16:42.077247+0530 Controller[851:11684] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x10470c970> (Domain: group.com.judepereira, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
2017-12-25 17:16:42.079711+0530 Controller[851:11707] [User Defaults] Couldn't write value for key idc in CFPrefsPlistSource<0x10470c620> (Domain: group.com.judepereira, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access, switching to read-only
2017-12-25 17:16:42.081354+0530 Controller[851:11707] [User Defaults] Couldn't write value for key rules in CFPrefsPlistSource<0x10470c620> (Domain: group.com.judepereira, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): Operation not allowed, switching to read-only

I've followed the guides specified here and here. Moreover, what's even more weird is that it works perfectly within the host app. I see these random errors only when my Message Filter Extension tries to update the user defaults for this app group.

Here's how I'm updating it:

NSUserDefaults *defaults = [[NSUserDefaults alloc]
                            initWithSuiteName:@"group.com.judepereira"];

NSLog(@"idc=%@", [defaults objectForKey:@"idc"]);
[defaults setObject:@"judepereira" forKey:@"idc"];

Further, I've read here and here about how a reboot of the device solves it, and also that these error messages are just some spurious warnings.

judepereira
  • 1,239
  • 2
  • 17
  • 24
  • I tried the opposite, getting a value from the host app always returns nil did you overcome it? Maybe it's not supported in this specific extension – itay83 Sep 19 '18 at 12:23

1 Answers1

1

After further investigation it's not allowed in this particular extension An answer from apple.

For privacy reasons, the system handles all communication with your associated server; your Message Filter app extension can't access the network directly.

Also for privacy reasons, your app extension can't write data to containers shared with the containing app.

You should not be writing data to a shared container for this particular type of Application Extension. Generally, you can use App Groups with NSUserDefaults to communicate information between your App and its Extensions.

itay83
  • 410
  • 1
  • 6
  • 18