Firebase (FCM) registration token in Flutter

前端 未结 4 1439
暗喜
暗喜 2021-02-12 14:26

I am trying to send notification from Java Rest Api (using Firebase Admin sdk) to my Flutter application and it seems it requ

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 15:07

    As you can the use the firebase Messaging Plugin to send the Notification. Through this code you can print the Token in Console.

    final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
    _firebaseMessaging.configure(
        onLaunch: (Map message) {
          print('onLaunch called');
        },
        onResume: (Map message) {
          print('onResume called');
        },
        onMessage: (Map message) {
          print('onMessage called');
        },
      );
      _firebaseMessaging.subscribeToTopic('all');
      _firebaseMessaging.requestNotificationPermissions(IosNotificationSettings(
        sound: true,
        badge: true,
        alert: true,
      ));
      _firebaseMessaging.onIosSettingsRegistered
          .listen((IosNotificationSettings settings) {
        print('Hello');
      });
      _firebaseMessaging.getToken().then((token) {
        print(token); // Print the Token in Console
      });
    }
    

提交回复
热议问题