Hi,
I try to use NSUserDefaults to share some parameter values between the container app and the system extension. I have added the App Group in Signing & Capabilities in both apps. I set it in the container app and read it in the system extension app, but the information I read from the system extension is nil. I tested that I can read the information directly from the container app. Is the system extension running in the sandbox not allowed to read other app information? But the information I see should be OK, as shown below:
The container app code is as follows:
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourcompany.shared"];
[sharedDefaults setObject:@"Sample Data" forKey:@"SharedData"];
[sharedDefaults synchronize];
The system expansion reading code is as follows:
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourcompany.shared"];
NSString *data = [sharedDefaults objectForKey:@"SharedData"];
os_log_debug(logHandle, "NSUserDefaults: %{public}@", data);
That won’t work. For an explanation as to why, and what you can do about it, see this post.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"