【问题标题】:onBackgroundMessage not getting called flutter messagingonBackgroundMessage 没有被称为颤振消息传递
【发布时间】:2021-05-16 19:04:23
【问题描述】:

在我的颤振应用程序上使用firebase messaging 时遇到了令人沮丧的体验,因为在发送请求后应用程序处于后台时,onBackgroundmessage 没有被触发。我想知道为什么这是我的应用需要的核心功能。

  Future initialize(context) async{
    _firebaseMessaging.configure(
   
    onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandler,

    
    );
  }
  Future<dynamic> _myBackgroundMessageHandler
      (Map<String, dynamic> message) async {
      print("onBackground Message called");
    fetchRideInfoInBackground();
    return Future<void>.value();
  }

}

通知负载

const message = {
      notification: {
        title: 'New Incoming Request',
        body: `New incoming ${service} request`,
      },
      data: { orderId: orderId },
      android: {
        ttl: 30,
        priority: 'high',
        notification: {
          click_action: 'FLUTTER_NOTIFICATION_CLICK',
        },
      },
      tokens: driversRegistrationToken,
    };

【问题讨论】:

    标签: flutter firebase-cloud-messaging


    【解决方案1】:

    我没有看到整个文件,但我认为您的 _myBackgroundMessageHandler 不是顶级函数。
    使其成为顶级或静态,之后它应该可以工作。

    编辑:示例

    
    Future<dynamic> _myBackgroundMessageHandler (Map<String, dynamic> message) async {
        print("onBackground Message called");
        fetchRideInfoInBackground();
        return Future<void>.value();
    }
    
     class PushHandler {
     
      final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
    
      Future initialize(context) async{
        _firebaseMessaging.configure(
          onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandler,
        );
      }
     }
    

    【讨论】:

    • 你能举个例子吗??
    • 用例子编辑
    • 还是不行吗兄弟?我也做到了顶级。你想让我展示完整的代码吗?
    • 也不适合我。 onBackgroundMessage 永远不会被调用
    猜你喜欢
    • 2021-04-18
    • 2020-01-23
    • 2021-03-08
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    相关资源
    最近更新 更多