如何在主iOS应用与其共享扩展之间使用相同的经过身份验证的用户令牌 [英] How to use same Authenticated user token between main iOS app and its Share Extension

查看:107
本文介绍了如何在主iOS应用与其共享扩展之间使用相同的经过身份验证的用户令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有与Firebase SDK集成的主应用程序.用户使用电子邮件,Google或Facebook通过主应用程序登录.

We have the main app integrated with Firebase SDK. User sign in via main application using email, google or facebook.

现在,我们已实施共享扩展程序,理想情况下,该扩展程序应在内部共享同一身份验证会话,以便可以在同一用户上通过Firebase发送数据,而无需要求他通过扩展程序再次登录.

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?

  1. 我们要么向主应用程序发送了一些内部调用以执行Firebase程序,因为其中包含身份验证详细信息.

  1. Either we sent some internal call to the main app to perform Firebase stuff because it has authentication detail within it.

主应用程序通过应用程序组为普通用户默认设置了一些令牌,共享扩展程序随后将使用这些令牌自动重新进行身份验证.

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.

或Firebase提供了一些方法,

Or Firebase provide some way to do so,

我不知道上面什么可行. 我找到了方法signInWithCustomToken:completion:,但是它与我实际寻找的内容无关.

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.

推荐答案

要从同一组NSUserDefaults中读取和保存,您需要执行以下操作:

To read and save from the same set of NSUserDefaults you need to the the following:

  1. 在主应用中,在项目导航器中选择项目.
  2. 选择您的主要应用目标,然后选择功能标签.
  3. 打开应用程序组(这将与开发人员门户进行通信,因为它会生成一组权利以及相关的应用程序ID等 来).
  4. 创建一个新容器.根据帮助,它必须开始 与"group."相对应,因此命名为"group.myapp.test".
  5. 选择 您的Today Extension目标,并重复此开启过程 应用组.不要创建一个新的,而是选择这个新创建的 组以表示Today Extension是该组的成员.
  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).
  4. Create a new container. According to the help, it must start with "group.", so give it a name like "group.myapp.test".
  5. Select your Today Extension target and repeat this process of switching on app groups. Don’t create a new one, rather select this newly created group to signify that the Today Extension is a member of the group.

写入您的NSUserDefaults:

Write to your NSUserDefaults:

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

从NSUserDefaults读取:

Read from NSUserDefaults:

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

if !firstLaunch  {
   ...
}

这篇关于如何在主iOS应用与其共享扩展之间使用相同的经过身份验证的用户令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆