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

前端 未结 1 1682
温柔的废话
温柔的废话 2021-01-21 13:55

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

Now, we have share extension implemented which ide

1条回答
  •  一生所求
    2021-01-21 14:15

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

    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.

    Write to your NSUserDefaults:

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

    Read from NSUserDefaults:

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

    0 讨论(0)
提交回复
热议问题