I've enabled local data sharing between my Parse application and iOS Today Extension following the official documentation here, making the necessary initialization calls in both the AppDelegate
of my app and the viewDidLoad
method of my extension, with the right key chains and app groups.
In the didFinishLaunchingWithOptions
method in AppDelegate
:
[Parse enableLocalDatastore];
[Parse enableDataSharingWithApplicationGroupIdentifier:@"group.com.my.app"];
[Parse setApplicationId:@"appId" clientKey:@"clientKey"];
In the viewDidLoad
method of my extension:
// Ensure Parse is only initialized once, otherwise an exception will be thrown
if(![Parse isLocalDatastoreEnabled]) {
[Parse enableDataSharingWithApplicationGroupIdentifier:@"group.com.my.app"
containingApplication:@"com.my.app"];
[Parse enableLocalDatastore];
// Setup Parse
[Parse setApplicationId:@"appId"
clientKey:@"clientKey"];
}
I could make queries in my extension, but I notice that if I start off in a logged state, go to my app and issue a logout, [PFUser currentUser]
remains non-nil in the extension (I can still access the information in the currentUser). Conversely, if I start off in a logged out state, go to the app, login and switch to my extension, [PFUser currentUser]
remains nil.
Any ideas on why changes in the logon status of the PFUser
are not synced across the app and its extensions?
If I had disabled isLocalDatastoreEnabled
check, the widget would crash on every second subsequent invocation, but when it is reloaded, at least the state of the currentUser
will be in sync, so this is all very puzzling.