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

camsedfj  于 11个月前  发布在  iOS
关注(0)|答案(2)|浏览(180)

伙计们,我试图从OneSignal推送通知中获取通知标题和正文我试图从JSON(如HTTP)中获取数据,但不起作用

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

字符串

beq87vna

beq87vna1#

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

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解决方案的参考

rsaldnfx

rsaldnfx2#

对于onesignal_flutter包版本:5.0.4

OneSignal.Notifications.addClickListener((event) {
      print("all events: $event");
      print("body is: ${event.notification.additionalData}");
    });

字符串

相关问题