如何提取消息标题和正文形式OneSignal推送通知Flutter

时间:2019-08-17 22:22:06

标签: android ios flutter onesignal

伙计们,我正在尝试从OneSignal推送通知中获取通知标题和正文,我曾尝试从JSON(如HTTP)中获取数据,但没有用

private Coroutine reScaleCoroutine;

private void OnTriggerEnter2D(Collider2D collision)
    {
     reScaleCoroutine = StartCoroutine(ReScale(new Vector3(.5f, .5f), new Vector3(0.1f, 0.1f), collision));
    }

private void StopCoroutineMethod()
    {
     StopCoroutine(reScaleCoroutine);
    }

1 个答案:

答案 0 :(得分:1)

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

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

中解决方案的参考