2

User is authorized in main app, and Firebase is initialized inside Today Extension:

// We check if FIRApp has already been configured with a static var, else it will crash...
    if !TodayViewController.isAlreadyLaunchedOnce {
        FirebaseApp.configure()
        TodayViewController.isAlreadyLaunchedOnce = true
    }

I've enabled Keychain Sharing as well and 2 times the currentUser property has returned the correct user but after that it always returns 'nil'

if let user = Auth.auth().currentUser

Is there something extra that should be done to make it working?

P.S. it's not related to guest user and there is not answer here: How to access current firebase user from iOS Today Extension? that's why it's not duplicate. I can't solve the problem by creating a duplicate user.

Thanks!

Alex
  • 475
  • 3
  • 14

2 Answers2

4

I'm faced with the same problem. Currently I dealt with it by copying the data contained in Keychain. This works, but I cannot say this is a valid solution.

https://gist.github.com/hhyyg/c1481853bcac27a678f707c0d1afd0f4

mono
  • 4,340
  • 3
  • 21
  • 49
hhyyg
  • 188
  • 1
  • 4
  • Thanks for answer! Trying to make it working at the moment. Could you please suggest from which fields the placeholders should be replaced? firebase_auth_{hosted app firebase application id}, firebase_auth_{app extension firebase application id}, firebase_auth_1___FIRAPP_DEFAULT_firebase_user - I've tried almost everything from GoogleService-Info.plist with no luck. Examples would be highly appreciated. Thanks! – Alex Mar 20 '18 at 05:40
  • Ok, finally it works! {hosted app firebase application id} = GOOGLE_APP_ID from GoogleService-Info.plist, __FIRAPP_DEFAULT works by default. Requires shared Keychain with the same group name. – Alex Mar 21 '18 at 05:06
  • This solution works for me. Using it a SiriKit extension – Tony Sep 06 '18 at 00:54
1

There 2 things that should be done to make it working:

  1. Share the same GoogleService-Info.plist between 2 projects (just don’t create separate as recommended, check your app extension in Target Membership in original one)
  2. Enable Keychain Sharing

Firebase shows some warning like:

4.9.0 - [Firebase/Core][I-COR000008] The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent. To continue with this plist file, you may change your app's bundle identifier to 'net.mybundle.mybundle’. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.

but works good so far..

P.S. sometimes changing GoogleService-Info.plist isn’t recognized by XCode and it uses old one. Make sure that you have the warning like “The project's Bundle ID is inconsistent with either the Bundle ID” … if no - try to disable app extension membership in all GoogleService-Info.plist and run the project (it should fail on Firebase initialization in app extension) after that just re-enable app extension membership and run one more time.

Alex
  • 475
  • 3
  • 14
  • There are one problem with this solution: after re-login in main app Today Extension is still logged in with old user. – Alex Mar 20 '18 at 05:43