0

I am working on a Flutter app that uses the FlutterFire firebase_messaging package.

I need to add delivery reports to my app, but the FlutterFire library does not support this.

So I must implement this native swift code.

But for this code to compile I must add the firebase-ios-sdk package to my 'Runner' project.

When building I now get the error...

Error (Xcode): redefinition of module 'Firebase'

Because both my Runner project and the FlutterFire dependency are both including the firebase-ios-sdk.

How can I import FirebaseMessaging in native swift code, while using the firebase-ios-sdk dependency that FlutterFire already imports?

If I try to add a library dependency from the existing flutter dependency (I go to General > Library Dependency > select "Pods > firebase_messaging"), the swift code is not able to resolve the 'import FirebaseMessaging' statement.

2
  • you have firebase messaging in flutter: pub.dev/packages/firebase_messaging/install if you want to use in appdelegate you must add it to pubspec.yaml and just use it to appdelegate, but you must have a copy from appdelegate. Commented May 3, 2022 at 12:23
  • clone FlutterFire and add your code in that package and refer cloned package in pubspec.yaml file. Now FlutterFire contain your code as well as FlutterFire original code Commented May 5, 2022 at 16:36

1 Answer 1

0

this works for me:

add your firebase package to pubspec.yaml

such as :

  firebase_messaging: ^11.2.14

enter image description here

after that if you want to add "this native swift code" implementation you must just import below to AppDelegate file:

import Firebase
import FirebaseMessaging

and

Messaging.serviceExtension().exportDeliveryMetricsToBigQuery(withMessageInfo:request.content.userInfo)

instead of

Messaging.extensionHelper()
      .exportDeliveryMetricsToBigQuery(withMessageInfo:request.content.userInfo)
  }

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

This does not work for me because my swift code is in a new App Extension target. Add a new target App Extension of type notification service extension, and try. This approach should not work in this case.
@Scorb you didn't mention it in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.