OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
615 stars 213 forks source link

setNotificationOpenedHandler not called #293

Closed ariona closed 4 years ago

ariona commented 4 years ago

Description:

All action inside setNotificationOpenedHandler are not getting called when user click on notification both when the app in foreground and on closed state.

Below is the code i used, to handle setNotificationOpenedHandler:

OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
  var notification = jsonDecode( result.notification.jsonRepresentation() );

  // this not called
  var data = jsonDecode(notification["custom"]);
  print( data["a"]["amount"] );

  // this not called
  Get.toNamed("/quran");

  // this not called
  Get.snackbar(
    "notification",
    "Clicked"
  );
});

The only logged data is from the library which is:

D/onesignal(14194): Created json raw payload: {vis=1, androidNotificationId=889645050, google.original_priority=normal, google.sent_time=1598609730184, pri=5, grp_msg=, google.delivered_priority=normal, custom={"a":{"amount":"100000"},"i":"0e471822-b839-4030-a27f-0cdb1ba40368"}, google.c.sender.id=624529927573, oth_chnl=, title=test, google.message_id=0:1598609730197327%f3e565b9f9fd7ecd, alert=tahu bulat, google.ttl=259200, from=624529927573}

Environment

  1. onesignal_flutter: ^2.6.1
  2. flutter SDK: 1.20.2

Device Info

  1. Android 10
  2. MIUI 11.0.9.0
  3. Pocophone F1

Steps to Reproduce Issue:

  1. I am using the code from example, and added some action on OpenedHandler
ariona commented 4 years ago

It's working now. had to check for additionalData payload first before running some actions :

OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
  if (result.notification.payload.additionalData.isNotEmpty) {
    var data = result.notification.payload.additionalData;

    print(data["amount"]);
  }
});