【问题标题】:Flutter FCM on resume on launch and on message not working in ios missing plugin implementation is triggered when launchFlutter FCM on resume on launch and on message not working in ios 缺少插件实现在启动时触发
【发布时间】:2020-04-02 02:56:36
【问题描述】:

Flutter FCM on resume on launch and on message not working in ios 缺少插件实现 dart 服务在启动时被触发,在 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));
  }

【问题讨论】:

  • 有同样的问题。运气好吗?
  • 目前问题未解决。

标签: ios flutter firebase-cloud-messaging


【解决方案1】:

尝试在您的 ios/Runner/AppDelegate.swift 中删除这些行:

if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }

我遇到了同样的问题,删除此代码后,我的应用运行良好。

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 2017-04-08
    • 2023-04-11
    • 2012-09-16
    • 2022-12-19
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 2021-10-22
    相关资源
    最近更新 更多