【问题标题】:Flutter can't catch notification with terminated ios applicationFlutter 无法捕获已终止 ios 应用程序的通知
【发布时间】:2021-03-02 15:45:36
【问题描述】:

所以我的应用程序要求我存储通知,以便用户稍后可以在屏幕上看到它们。

无论应用程序正在运行、在后台还是已终止,在 Android 上一切正常。 对于 ios,我可以在应用程序运行时捕获通知。

但问题是每当应用程序终止时,我仍然可以发送 ios 通知并且设备显示通知但数据有效负载未注册 (如果应用程序被终止但用户点击通知并启动应用程序,它也可以工作)

这是 fcm 配置代码 show notification 只是显示通知的本地通知插件,它将通知保存在共享首选项中。

_fcm.configure(
      onBackgroundMessage: Platform.isIOS ? null : backgroundMessageHandler,
      onMessage: (Map<String, dynamic> message) async {
        logger.d("onMessage: $message");
        try {
          showNotifications(message);
        } catch (e) {
          print('PushNotificationService.initialise error: $e');
        }
      },
      onLaunch: (Map<String, dynamic> message) async {
        logger.d("onLaunch: $message");
        showNotifications(message);
      },
      onResume: (Map<String, dynamic> message) async {
        try {
          logger.d("onResume: $message");
          showNotifications(message);
        } catch (e) {
          print('PushNotificationService.initialise e: $e');
        }
      },
    );

那么有没有办法在 ios 应用程序终止的情况下捕获和处理数据负载。

【问题讨论】:

  • 在 iOS 上,通知不会唤醒后台应用。当您在后台收到通知时,您的应用程序中不会运行任何代码。如果您在收到通知时需要做某事,那么您必须实现一个通知服务应用扩展:developer.apple.com/documentation/usernotifications/… 不过,不确定如何使用颤振来做到这一点。

标签: ios firebase flutter firebase-cloud-messaging flutter-ios


【解决方案1】:

您需要在 Xcode 的签名和功能部分添加功能以进行推送通知。

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    相关资源
    最近更新 更多