firebase / quickstart-ios

Firebase Quickstart Samples for iOS
https://firebase.google.com
Apache License 2.0
2.78k stars 1.47k forks source link

iOS Extensions Support #797

Open mhdhejazi opened 4 years ago

mhdhejazi commented 4 years ago

I'm trying to add Firebase to an iMessage app extension. I created a project in Firebase and added two iOS apps, one for the main app (id: com.company.app), and the other for the extension (id: com.company.app.stickers). I followed the guides and added the proper GoogleService-Info.plist file to each target. But when I run the extension I see error this in Xcode output:

6.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 'com.company.app.stickers'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.

I made sure the bundle identifier of the extension is actually com.company.app.stickers. But the interesting thing is that when I tried to use the main GoogleService-Info.plist for the extension target the error disappeared although the bundle id in this plist file is com.company.app and the bundle id of the extension target is different!

So, am I doing anything wrong here? Or iOS extensions are not supported?

morganchen12 commented 4 years ago

Extensions are not officially supported, but some Firebase SDKs do work in extensions. In this case it's fine to use the main GoogleService-Info.plist file in the extension.

mhdhejazi commented 4 years ago

Does the error make sense though? I mean what's the cause of the bundle id inconsistency here? And why does it accept the main GoogleService-Info.plist that contains the main app id? Does Firebase check the current bundle id or the root bundle's one? I think this is a bit confusing and deserves a note in the documentation.

mhdhejazi commented 4 years ago

P.S. I needed to create a different app in my Firebase project with the bundle id of the extension for Crashlytics to work. This makes things more confusing now. Crashlytics needs a different app in Firebase but I should not use its GoogleService-Info.plist?

morganchen12 commented 4 years ago

Hm, that's definitely not good. Some background: The first warning message you got was from Analytics, which will discard some early lifecycle logs if the GoogleService-Info.plist has a mismatched bundle ID but otherwise work fine. Crashlytics is more restrictive, since it uses the bundle id to uniquely identify your binary. Since your extension is a separate process from your main app, you'll most likely need to use a separate GoogleService-Info.plist and just ignore the Analytics warning log.

We'll look into ways to make this experience better.

inPhilly commented 4 years ago

This error is still happening. It's confusing to the user and it should be resolved. Many apps use app extensions and need crash reporting for them.

inPhilly commented 4 years ago

Also, I can't verify my app extension because of this issue. Everything is setup correctly (two apps in same project, two files, each with their respective target), but this error is stopping the verification.

inPhilly commented 4 years ago

We'll look into ways to make this experience better.

Any progress on this front?

morganchen12 commented 4 years ago

No. This is a lower priority for us than macOS native and Catalyst support.

jeffreyrobert commented 4 years ago

@morganchen12 thanks for the update! Is there anywhere for us to know which Firebase SDKs will work and which won't?

For example, after a bit of work I have Analytics working (minus a few issues), but I don't have Crashlytics working. Would be great to know if this can work in iMessage Extensions or not before I pour the time in.

Thanks in advance!

morganchen12 commented 4 years ago

We don't have a matrix of which platforms are supported by which Firebase components. Crashlytics will probably work if you can set up the extension as a separate app and convince Crashlytics it's just reporting another app's crashes.

With this year's WWDC adding even more emphasis on non-app targets in the Apple ecosystem, we've increased the pressure internally to provide first-class support for non-app Apple platforms targets, but I don't have any concrete news or timelines to share.

tehsven commented 4 years ago

@jeffreyrobert do you mind sharing how you were able to get Analytics working for your extension? I set up my app with two Info plist files like the original post, but no analytics were being reported.

jeffreyrobert commented 3 years ago

@tehsven sorry for the delay. Hope you were able to get it working, if not (and for others). This is my current setup.

It seems that the Firebase team has made a lot of improvements this year (2020) in regards to Extension support for their SDKs. I updated to the latest SDKs and everything worked pretty smoothly for me. Here's my setup:

Bundle ID I believe the recommended setup is to use your Main App Target's bundle ID for your Firebase app. So do not include the .MessagesExtension. I set my app up before this was possible, so my Firebase app is using my iMessage Extension Target's bundle ID including .MessagesExtension. This may give me issues down the line but I don't actually have a Main App, my app is a standalone iMessage Extension.

Initialization

    override func willBecomeActive(with conversation: MSConversation) {

        // need to do this check to handle instances of application running in transcript view
        // note this check will cause this log:
        // [Firebase/Core][I-COR000005] No app has been configured yet.

        if let firebaseApps = FirebaseApp.allApps,
            !firebaseApps.isEmpty {

            // already configured

        } else {
            FirebaseApp.configure()
        }

Versions