2

I have configured firebase messaging in flutter app. It use firebase messaging plugin. I have configured according to "iOS Integration" section from readme. Firebase is inited in main.dart

void main() async {
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  _firebaseMessaging.requestNotificationPermissions();
  _firebaseMessaging.configure(onMessage: processMessage,
      onLaunch: processLaunch,
      onResume: processResume);
  String token = await _firebaseMessaging.getToken();
  print("fcm token is: $token");
  runApp(TestApp());
}

Future<dynamic> processMessage(Map<String, dynamic> map) async {
  print("received message:");
  print(map);
}

Future<dynamic> processLaunch(Map<String, dynamic> map) async {
  print("processing launch");
  print(map);
}

Future<dynamic> processResume(Map<String, dynamic> map) async {
  print("processing resume");
  print(map);
}

The problem is app don't receive token. So I deploy application to physical device, application starts, but don't see any output related to fcm, and ui not shown. I see following logs in IDEA:

5.10.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: .
5.10.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging

Where can be problem?

2 Answers 2

4

It started to work when I moved firebase code to TestApp, seems like main.dart is wrong place for fcm code. I placed it inside initState.

2
  • sorry.. what exactly do you mean by TestApp?
    – Amir Aslam
    Dec 1, 2020 at 13:38
  • @Amir Aslam It is main widget Dec 2, 2020 at 7:42
0

As of October 11 2018, the getToken implementation is faulty (see issues 17699 and 20378).

There's a pull request to fix it, but it's still pending.

For now, in order to avoid problems with getToken, I would suggest listening to onTokenRefresh (that's what I do).

I didn't test the code below, but it's just an example of how you would have to adapt your code.

String _token;

void main() async {
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  _firebaseMessaging.requestNotificationPermissions();

  Stream<String> fcmStream = _firebaseMessaging.onTokenRefresh;
  fcmStream.listen((token) {
    // saveToken(token);
    print("fcm token is: $token");
    _token = token;     
  });

  _firebaseMessaging.configure(onMessage: processMessage,
      onLaunch: processLaunch,
      onResume: processResume);

  runApp(TestApp());
}
1
  • Thanks for your response @Feu, in my case it started to work when I moved firebase related code inside TestApp, initState method Oct 11, 2018 at 18:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.