android - 如何从 OneSignal 推送通知 Flutter 中提取消息标题和正文

标签 android ios flutter onesignal

伙计们,我正在尝试从 OneSignal 推送通知中获取通知标题和正文我已经尝试从像 HTTP 一样的 JSON 中获取数据,但它没有用

OneSignal.shared
        .setNotificationReceivedHandler((OSNotification notification) {
      // will be called whenever a notification is received

      print('Recived Notification is : $notification');

      notification.convertToJsonString({'title': title, 'alert': body});

      print('Title is : $title');
      print('Description is : $body');
    });


onesignal( 9471): Created json raw payload: {vis=1, google.original_priority=normal, google.sent_time=1566080374593, pri=5, grp_msg=, google.delivered_priority=normal, custom={"i":"cb91f929-3008-4364-a687-1675448c2d0a"}, oth_chnl=, title=Welcom test Notification, google.message_id=0:1566080374598190%ab53bc02f9fd7ecd, alert=this is description of welcome text content notification, google.ttl=259200, from=613584415888, notificationId=173367476}
I/flutter ( 9471): Recived Notification is : Instance of 'OSNotification'
I/flutter ( 9471): Title is : null
I/flutter ( 9471): Description is : null

最佳答案

我已经解决了我的问题,它只是像这样获取通知的有效负载

OneSignal.shared
      .setNotificationReceivedHandler((OSNotification notification) {
    // will be called whenever a notification is received

    print('Recived Notification is : $notification');

    title = notification.payload.title;
    body = notification.payload.body;
  });

这是来自 OneSignal Docs 的解决方案引用

关于android - 如何从 OneSignal 推送通知 Flutter 中提取消息标题和正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57540349/

相关文章:

flutter - 从 Assets 设置本地通知自定义声音

android - RecyclerView ItemTouchHelper 轻扫

android - 如何在按钮内的图标和文本之间添加分隔符?

ios - 如何在 swift 4 中使用 json 对象发送 json 数据

ios - iOS 11 中未调用用户当前位置委托(delegate)方法

flutter - 使用提供程序和 snackbar 查找停用的小部件的祖先是不安全的

IOS 上的 Android post 请求

c# - OpenCV:cv::Mat 无法从看似有效的数据中创建矩阵

ios - 解析查询不返回完整的对象详细信息

flutter - 第一个字符为高位,其余部分为低位