From time to time, but not always (I have had this working for a bit), the app/extension gets in a state where I can't read a flag set in my App Group between my companion app and my app extension. Don't know how it gets in this state or why the values differ, but it's critical to my application these always be in sync.
Companion app viewDidLoad:
NSUserDefaults *myAppSettings = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp"];
.....
[myAppSettings setBool:true forKey:@"myBool"];
[myAppSettings synchronize];
NSLog([myAppSettings boolForKey:@"myBool"] ? @"Companion app - bool TRUE" : @"Companion app - bool FALSE");
App extension viewDidLoad
NSUserDefaults *myAppSettings = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp"];
[myAppSettings synchronize];
NSLog([myAppSettings boolForKey:@"myBool"] ? @"App extension app - bool TRUE" : @"App extension - bool FALSE");
Console output
Companion app - bool TRUE
App extension - bool FALSE
I also synchronize before my companion app will enter background. I have my app group set up in the portal etc.
What am I doing wrong?
EDIT
Apparently others having this problem too: https://devforums.apple.com/message/977151#977151
"I think that this is currently very glitchy.
Sometimes the data sharing works, then a change and all of a sudden the widget can't see the shared data anymore (both on Simulator and device).
Annoying and hope it's a bit more reliable in next beta!"
EDIT 2 Looks like another person has reported this exact issue as well:
"I also noticed the same thing too.This not only happen to the NSUserDefaults, but also all the files in the container folder. The keyboard extension suddenly will lose read/write pemission to the container folder after using the keyboard for a while."
EDIT 3 More evidence: https://devforums.apple.com/message/1028078#1028078
After I upgrade to beta 3, I noticed that sometimes the keyboard failed to open the database because it failed to access to the DB file. The keyboard has been able to access to the file before.
EDIT 4
Seems like this could be because the keyboard loses the RequestsOpenAccess
flag. But I can't reproduce it, and there's no way for me to tell for sure.
EDIT 5
Seems like others are reporting this in the iOS8 GM build:
This issue still persists for me in the GM. It seems related to a keyboard crash.. but also there seems to be some contention between keyboard and containing app in terms of who creates the suite in what order. I think this problem is on Apple's end. Trust me, I WANT it to be my fault but I've spent countless hours with trial and error. No matter what I do in code and verify with NSLog, it will end up in this state eventually. Hoping someone finds a magic pill. :S
Has anyone solved this yet?