简体   繁体   English

iOS App Extension将PFUser currentUser设置为nil

[英]iOS App Extension has PFUser currentUser set to nil

I have a Parse-enabled iOS 8 app and I'm trying to enable Share Extension. 我有一个启用了Parse的iOS 8应用程序,并且正在尝试启用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. 我已经按照 https://www.parse.com/docs/ios/guide#extensions上的 [PFUser currentUser]进行了准确的操作 ,但是在我的应用扩展程序中, [PFUser currentUser]设置为nil (而在我的应用程序中不为nil) ,并且[PFInstallation currentInstallation]设置为新实例,而不是我现有的安装。 There seems to be a problem with App Extension communicating with my app. App Extension与我的应用进行通信似乎存在问题。

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. 如果您已有使用Parse SDK的应用程序,则当用户升级到最新的应用程序版本(启用了数据共享)时,Parse SDK将自动移动主应用程序的本地持久性数据(Local Datastore,当前PFUser,当前PFInstallation等)从应用程序的沙箱容器到共享容器。

I have enabled Keychain Sharing and App Groups with the same IDs, and added the appropriate code. 我已启用具有相同ID的钥匙串共享和应用组,并添加了适当的代码。 Why am I still getting nil as the current user in my extension? 为什么我在扩展程序中仍然是nil用户? I am on the latest Parse iOS SDK (1.7.4). 我正在使用最新的Parse iOS SDK(1.7.4)。

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]; 添加[Parse enableLocalDatastore]; before initializing Parse and after data sharing code ( enableDataSharingWithApplicationGroupIdentifier:containingApplication: ) solved my problem. 初始化Parse之前和数据共享代码( enableDataSharingWithApplicationGroupIdentifier:containingApplication:之后解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM