简体   繁体   English

如何在主iOS应用与其共享扩展之间使用相同的经过身份验证的用户令牌

[英]How to use same Authenticated user token between main iOS app and its Share Extension

We have the main app integrated with Firebase SDK. 我们有与Firebase SDK集成的主应用程序。 User sign in via main application using email, google or facebook. 用户使用电子邮件,Google或Facebook通过主应用程序登录。

Now, we have share extension implemented which ideally should share same Authentication session internally so that data can be sent on Firebase with the same user without asking him to login again through the extension. 现在,我们实现了共享扩展,理想情况下应该在内部共享同一身份验证会话,以便可以与同一用户在Firebase上发送数据,而无需要求他通过扩展再次登录。

So, does anyone know the way to share Firebase authentication session between the Main app and share extension? 那么,有人知道在主应用程序和共享扩展之间共享Firebase身份验证会话的方式吗?

  1. Either we sent some internal call to the main app to perform Firebase stuff because it has authentication detail within it. 我们要么向内部应用程序发送了一些内部调用以执行Firebase程序,因为其中包含身份验证详细信息。

  2. The main app set some token to common user defaults via app groups which will be then used by Share extension to re-authenticate automatically. 主应用程序通过应用程序组为普通用户默认设置了一些令牌,共享扩展程序将使用这些令牌自动重新进行身份验证。

  3. Or Firebase provide some way to do so, 或Firebase提供了一些方法,

I don't know what is feasible from above. 我不知道什么是可行的。 I found a method signInWithCustomToken:completion: but, it's not related to what I actually looking for. 我发现了一个方法signInWithCustomToken:completion:但是它与我实际寻找的内容无关。

To read and save from the same set of NSUserDefaults you need to the the following: 要从同一组NSUserDefaults中读取和保存,您需要执行以下操作:

  1. In your main app, select your project in the project navigator. 在您的主应用程序中,在项目导航器中选择您的项目。
  2. Select your main app target and choose the capabilities tab. 选择您的主要应用目标,然后选择功能选项卡。
  3. Switch on App Groups (this will communicate with the developer portal, as it is generating a set of entitlements, and relevant App Id and so forth). 打开应用程序组(这将与开发人员门户进行通信,因为它正在生成一组权利以及相关的应用程序ID等)。
  4. Create a new container. 创建一个新的容器。 According to the help, it must start with “group.”, so give it a name like “group.myapp.test”. 根据帮助,它必须以“ group。”开头,因此应命名为“ group.myapp.test”。
  5. Select your Today Extension target and repeat this process of switching on app groups. 选择您的Today Extension目标,然后重复此打开应用程序组的过程。 Don't create a new one, rather select this newly created group to signify that the Today Extension is a member of the group. 不要创建一个新的组,而是选择这个新创建的组以表示Today Extension是该组的成员。

Write to your NSUserDefaults: 写入您的NSUserDefaults:

    // In this example I´m setting FirstLaunch value to true 
NSUserDefaults(suiteName: "group.myapp.test")!.setBool(true, forKey: "FirstLaunch")

Read from NSUserDefaults: 从NSUserDefaults读取:

// Getting the value from FirstLaunch
let firstLaunch = NSUserDefaults(suiteName: "group.myapp.test")!.boolForKey("FirstLaunch")

if !firstLaunch  {
   ...
}

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

相关问题 在iOS App及其扩展程序之间共享情节提要 - Share Storyboard between iOS App and its Extension 主应用程序和共享扩展名之间的iOS共享.h文件 - iOS Sharing .h file between main app and share extension 在 iOS 8 共享扩展和主应用程序之间共享数据 - Sharing data between an iOS 8 share extension and main app 如果用户安装了主应用程序,iOS共享扩展程序是否会自动安装? - Is that an iOS share extension will be installed automatically if user installed your main app? 使用钥匙串在 iOS 扩展程序及其包含的应用程序之间共享? - Share between an iOS extension and its containing app with the keychain? 在iOS8中的App和App Extension之间共享用户对象 - Share User Object between App and App Extension in iOS8 如何在 iOS 中的扩展和主机应用程序之间共享后删除数据 - How to remove data after share between extension and host app in iOS 在iOS App和WatchKit Extension之间共享Plist - Share Plist between iOS App and WatchKit Extension 如何与我的主应用程序和 iOS 应用程序的应用程序扩展正确共享 Amplify 框架? - How can I properly share the Amplify framework with my Main App and my App Extension for an iOS app? iOS使用Alamofire快速在应用程序和共享扩展之间共享Cookie - iOS swift using alamofire to share cookie between app and share extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM