问题
I have a Parse-enabled iOS 8 app and I'm trying to enable Share Extension. I've done exactly what it says at https://www.parse.com/docs/ios/guide#extensions but in my app extension, [PFUser currentUser]
is set to nil
(while it is not nil in my app), and [PFInstallation currentInstallation]
is set to a new instance instead of my existing installation. There seems to be a problem with App Extension communicating with my app.
In the Parse docs it clearly states:
If you have an existing app using the Parse SDK, when users upgrade to your latest app version (with data sharing enabled), the Parse SDK will automatically move the main app's local persistent data (Local Datastore, current PFUser, current PFInstallation, etc) from the app's sandbox container to the shared container.
I have enabled Keychain Sharing and App Groups with the same IDs, and added the appropriate code. Why am I still getting nil
as the current user in my extension? I am on the latest Parse iOS SDK (1.7.4).
回答1:
Found the problem:
I wasn't enabling local datastore in the app extension. Data store must be enabled both in the app itself and the app extension. Adding [Parse enableLocalDatastore];
before initializing Parse and after data sharing code (enableDataSharingWithApplicationGroupIdentifier:containingApplication:
) solved my problem.
来源:https://stackoverflow.com/questions/30429294/ios-app-extension-has-pfuser-currentuser-set-to-nil