Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification payload userInteraction always false #152

Closed
gibrandev opened this issue Jul 14, 2020 · 24 comments
Closed

Notification payload userInteraction always false #152

gibrandev opened this issue Jul 14, 2020 · 24 comments

Comments

@gibrandev
Copy link

I am always received userInteraction false, if click notification always userInteraction false. I dont know this bug or not. Anyone can help me?

@TaraSinghDanu
Copy link

TaraSinghDanu commented Jul 21, 2020

Facing Same issue..... 😐

@Dallas62
Copy link
Contributor

Dallas62 commented Sep 2, 2020

#122

@gibrandev
Copy link
Author

Thanks @Dallas62 i will try it tomorrow

@Dallas62
Copy link
Contributor

This issue should be fixed now 😉

@kyytiPetteri
Copy link

I had a different case to this on iOS:

userInteraction prop is false when application is on the foreground. We use in app notifications so not really a big problem.

However when notification is in the background and killed state no matter if there is user interaction or not the userInteraction prop is always true.

Using:

    "@react-native-community/push-notification-ios": "1.3.0",
    "react-native-push-notification": "^4.0.0",
    "react-native": "^0.63.2",

@gibrandev
Copy link
Author

@Dallas62 still not working

@Dallas62
Copy link
Contributor

You need to install the latest version of the iOS library

@TommyLeong
Copy link

TommyLeong commented Sep 17, 2020

@Dallas62 I have updated to the latest iOS library "@react-native-community/push-notification-ios": "^1.5.0" here's what happened. The results below are tested with Firebase Console, on a real iPhone device.

Foreground

Received notification (while App at Foreground)

{
  "data": {
    "deeplink": "myapp://profile"
  },
  "messageId": "1600313175552426",
  "mutableContent": true,
  "notification": {
    "body": "Welcome to my app",
    "ios": {
      
    },
    "sound": "default",
    "title": "MyTitle"
  },
  "sentTime": "1600314145"
}

After Tapping notification (while App at Foreground)

{
  "badge": undefined,
  "data": {
    "userInteraction": 1
  },
  "finish": [
    Functionfinish
  ],
  "foreground": true,
  "id": undefined,
  "message": "Welcome to my app",
  "soundName": undefined,
  "title": "MyTitle",
  "userInteraction": false
}

Background

Received notification (while App at Background)
N/A - JS don't run at background

After Tapping notification (while App at Background)

{
  "badge": undefined,
  "data": {
    "aps": {
      "alert": [
        Object
      ],
      "mutable-content": "1",
      "sound": "default"
    },
    "deeplink": "myapp://profile",
    "gcm.message_id": "I_HAVE_MASKED_THE_VALUE_HERE",
    "gcm.n.e": "1",
    "gcm.notification.sound2": "default",
    "google.c.a.c_id": "I_HAVE_MASKED_THE_VALUE_HERE",
    "google.c.a.e": "1",
    "google.c.a.ts": "I_HAVE_MASKED_THE_VALUE_HERE",
    "google.c.a.udt": "0",
    "google.c.sender.id": "I_HAVE_MASKED_THE_VALUE_HERE",
    "userInteraction": 1
  },
  "finish": [
    Functionfinish
  ],
  "foreground": false,
  "id": undefined,
  "message": "Welcome to my app",
  "soundName": undefined,
  "title": "MyTitle",
  "userInteraction": true
}

My questions:

  1. Foreground: We are suppose refer to userInteraction returned in data? Since it's returning 1 to me.
  2. Foreground: Spotting that my deeplink is missing in data after tapping on it. Is this expected?

@Dallas62
Copy link
Contributor

Hi @TommyLeong
Can you test with a version before this PR: #122

Actually this should not have impacted the userInfo value, or the name of the property changed on "click".
https://github.com/react-native-community/push-notification-ios/pull/122/files

@TommyLeong
Copy link

@Dallas62 i'm not using hook, im getting my notification here.

PushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function (token) {
    console.log("TOKEN:", token);
  },

  // (required) Called when a remote is received or opened, or local notification is opened
  onNotification: function (notification) {
    console.log("NOTIFICATION:", notification);

    // IM GETTING MY NOTIFICATION HERE

    // (required) Called when a remote is received or opened, or local notification is opened
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },
...etc codes
....etc codes
......etc codes

@Dallas62
Copy link
Contributor

Yes but can you test with an older version of react-native-community/push-notification-iosprior to #122 to see the result ?

@TommyLeong
Copy link

@Dallas62 Here's the result with 1.4.1 on iOS, with physical device tested. I hope this is clear to you. The data is missing after tapping notification at foreground.

Foreground

Received notification (while App at Foreground)

{
  "data": {
    "deeplink": "myapp://profile"
  },
  "messageId": "1600323847995493",
  "mutableContent": true,
  "notification": {
    "body": "Welcome to my app",
    "ios": {
      
    },
    "sound": "default",
    "title": "MyTitle"
  },
  "sentTime": "1600326575"
}

After Tapping notification (while App at Foreground)

{
  "badge": undefined,
  "data": {
    
  },
  "finish": [
    Functionfinish
  ],
  "foreground": true,
  "id": undefined,
  "message": "Welcome to my app",
  "soundName": undefined,
  "title": "MyTitle",
  "userInteraction": false
}

Background

Received notification (while App at Background)
N/A - JS don't run at background

After Tapping notification (while App at Background)

{
  "badge": undefined,
  "data": {
    "aps": {
      "alert": [
        Object
      ],
      "mutable-content": "1",
      "sound": "default"
    },
    "deeplink": "myapp://profile",
    "gcm.message_id": "I_HAVE_MASKED_THE_VALUE_HERE",
    "gcm.n.e": "1",
    "gcm.notification.sound2": "default",
    "google.c.a.c_id": "I_HAVE_MASKED_THE_VALUE_HERE",
    "google.c.a.e": "1",
    "google.c.a.ts": "I_HAVE_MASKED_THE_VALUE_HERE",
    "google.c.a.udt": "0",
    "google.c.sender.id": "I_HAVE_MASKED_THE_VALUE_HERE"
  },
  "finish": [
    Functionfinish
  ],
  "foreground": false,
  "id": undefined,
  "message": "Welcome to my app",
  "soundName": undefined,
  "title": "MyTitle",
  "userInteraction": true
}

@Dallas62
Copy link
Contributor

Thanks for the feed back, so it's not related to the PR of userInteraction. I will try to find time to investigate on this.

@TommyLeong
Copy link

Back to my question earlier, we are suppose refer to userInteraction returned in data? Since it's returning 1 to me.

@Dallas62
Copy link
Contributor

If you are using the iOS library, yes.
I saw you are using the zo0r/react-native-push-notification library, you will have to wait for: zo0r/react-native-push-notification@bedc8f6
I'm a bit busy actually to finish the release. I will try to release it this weekend.

@TommyLeong
Copy link

Yup. Using both zo0r/react-native-push-notification and this library. Alright, appreciate bro! I'll create a separate issue for the data missing.

@gibrandev
Copy link
Author

@TommyLeong in my case, everything is fine. Could you please give AppDelegate.m, maybe I can help you

@TommyLeong
Copy link

@gibrandev When you say everything is fine, are you getting the same response like mine?

Getting the "userInteraction": 1 within data

{
  "badge": undefined,
  "data": {
    "userInteraction": 1
  },
  "finish": [
    Functionfinish
  ],
  "foreground": true,
  "id": undefined,
  "message": "Welcome to my app",
  "soundName": undefined,
  "title": "MyTitle",
  "userInteraction": false
}

@gibrandev
Copy link
Author

Yes like this
https://github.com/react-native-community/push-notification-ios#how-to-determine-push-notification-user-click
i think this is not a problem, because already in the readme. and in my case all notification inside in data

@TommyLeong
Copy link

Yup, then we are getting the same. I was just confirming with Dallas whether this is expected. Apparently this is the case

If you are using the iOS library, yes.
I saw you are using the zo0r/react-native-push-notification library, you will have to wait for: zo0r/react-native-push-notification@bedc8f6
I'm a bit busy actually to finish the release. I will try to release it this weekend.

@gibrandev
Copy link
Author

Maybe you can modification this, before #122 i am used this.
This same with #122 maybe you can change that outside of the data
If you want 😄

// Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
      willPresentNotification:(UNNotification *)notification
        withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  // Still call the JS onNotification handler so it can display the new message right away
  NSDictionary *userInfo = notification.request.content.userInfo;
  NSMutableDictionary *userInfoCopy = [userInfo mutableCopy];
  userInfoCopy[@"userInteraction"] = @false;
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfoCopy
                                fetchCompletionHandler:^void (UIBackgroundFetchResult result){}];

  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application
  didReceiveRemoteNotification:(NSDictionary *)userInfo
  fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  NSMutableDictionary *userInfoCopy = [userInfo mutableCopy];
  userInfoCopy[@"userInteraction"] = @true;
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfoCopy fetchCompletionHandler:completionHandler];
}

@gibrandev
Copy link
Author

Maybe you can modification this, before #122 i am used this.
This same with #122 maybe you can change that outside of the data
If you want 😄

// Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
      willPresentNotification:(UNNotification *)notification
        withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  // Still call the JS onNotification handler so it can display the new message right away
  NSDictionary *userInfo = notification.request.content.userInfo;
  NSMutableDictionary *userInfoCopy = [userInfo mutableCopy];
  userInfoCopy[@"userInteraction"] = @false;
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfoCopy
                                fetchCompletionHandler:^void (UIBackgroundFetchResult result){}];

  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application
  didReceiveRemoteNotification:(NSDictionary *)userInfo
  fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  NSMutableDictionary *userInfoCopy = [userInfo mutableCopy];
  userInfoCopy[@"userInteraction"] = @true;
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfoCopy fetchCompletionHandler:completionHandler];
}

@Dallas62 maybe you can help us. 😄

@gibrandev
Copy link
Author

closed #122

@ys-sherzad
Copy link

@TommyLeong Have you found a solution for the missing data!! I can capture the data in Android but in iOS it's overwritten for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants