开发者社区> 问答> 正文

FLUTER FCM On Resume on Launch和on Message Not Work

启动时触发FCM,在Android上运行良好以下是用于处理FCM的代码。iOS通知是在后台应用程序和打开单击应用程序时触发的。

_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print(message);
        FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
            new FlutterLocalNotificationsPlugin();
        // initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
        var initializationSettingsAndroid =
            new AndroidInitializationSettings('launcher_icon');
        var initializationSettingsIOS = new IOSInitializationSettings(
            onDidReceiveLocalNotification: onDidReceiveLocalNotification);
        var initializationSettings = new InitializationSettings(
            initializationSettingsAndroid, initializationSettingsIOS);
        flutterLocalNotificationsPlugin.initialize(initializationSettings,
            onSelectNotification: onSelectNotification);
        var androidPlatformChannelSpecifics = AndroidNotificationDetails(
            '123', 'convoy notification', 'convoy notification',
            importance: Importance.Max,
            priority: Priority.High,
            ticker: 'ticker');
        var iOSPlatformChannelSpecifics = IOSNotificationDetails();
        var platformChannelSpecifics = NotificationDetails(
            androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
        await flutterLocalNotificationsPlugin.show(
            0,
            message['notification']['title'],
            message['notification']['body'],
            platformChannelSpecifics,
            payload: message['data']['payload']);
      },
      onBackgroundMessage: myBackgroundMessageHandler,
      onLaunch: (Map<String, dynamic> message) async {
        var string = message["data"]["payload"];
        var payload = jsonDecode(string);
        print(payload);
        if (payload != null) {
          var type = payload["refresh"];
          if (type == "OFFERS") {
            Future.delayed(Duration(seconds: 3), () {
              _navigateToOffers(payload["id"]);
            });
          } else if (type == "REQUESTS") {
            Future.delayed(Duration(seconds: 3), () {
              _navigateToRequests(payload["id"]);
            });
          }
        }
        //_navigateToItemDetail(message);
      },
      onResume: (Map<String, dynamic> message) async {
        var string = message["data"]["payload"];
        var payload = jsonDecode(string);
        print(payload);
        if (payload != null) {
          var type = payload["refresh"];
          if (type == "OFFERS") {
            _navigateToOffers(payload["id"]);
          } else if (type == "REQUESTS") {
            _navigateToRequests(payload["id"]);
          }
        }
        // _navigateToItemDetail(message);
      },
    );
    _firebaseMessaging.requestNotificationPermissions(
        const IosNotificationSettings(sound: true, badge: true, alert: true));
  }

展开
收起
游客5akardh5cojhg 2019-12-09 14:00:21 513 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Fighting Cybercrime: A Joint Task Force of Real-Time Data and Human Analytics 立即下载
Cloak-And-Dagger-From-Two-Permissions-To-Complete-Control-Of-The-UI-Feedback-Loop 立即下载
Top Five Mistakes Made When Writing Streaming App 立即下载