How to access current firebase user from iOS Today Extension?

你说的曾经没有我的故事 提交于 2019-12-19 08:27:32

问题


We're building a today widget on top of our iOS app which is working with Firebase. However we're struggling to access current signed-in user from the extension. The user at the main app is anonymous so passing credentials via shared container is not an option.

The only way that I found is passing uid and generate custom token to sign in but I was hoping to find out better way to share FIRUser between my main app and app extension. What would be the best way to achieve this?


回答1:


You can share data between Host App and App Extension only using App Group. There is no way of direct communication between your Host App and App Extension.

Even though an app extension bundle is nested within its containing app’s bundle, the running app extension and containing app have no direct access to each other’s containers.

App Group is a shared container used by both Host App as well as App Extension. It is like UserDefaults that store key-value pairs.

So you can save your current user information in App Group from Host App and then access it in your Today Extension from the same App Group.

For more on App Groups refer to: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html



来源:https://stackoverflow.com/questions/44635989/how-to-access-current-firebase-user-from-ios-today-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!