React-native-push-notification: userInteraction always returns true on iOS

Created on 10 Jul 2017  路  9Comments  路  Source: zo0r/react-native-push-notification

Hi guys,

I'm facing an issue since few days that I don't understand.

Here is the content of the notification I'm pushing via AWS SNS:

{
"APNS_SANDBOX":"{\"aps\":{\"alert\":{\"title\":\"My App\", \"body\":\"Body notif\",\"payload\":{\"type\":\"new_post\"}},\"sound\":\"default\", \"content-available\":\"1\"}}"
}

onNotification is triggered when I receive the notification and a second time when I open the notification. Which is the expected behaviour.

foreground is always false, which is the expected behaviour when the app is on background or when I click on the notification. It's true when the app is on foreground.

The problem is when I want to check userInteraction. The value is always true wether I receive the notification or click on it.

I tried different scenario but userInteraction is always true.

Is it normal? Am I the only one having this behaviour?
If someone has an idea on what I'm doing wrong, I would love to hear from him.

Thanks for your help.

Stale

Most helpful comment

From this post I was able to trigger the method onNotification only when user taps on notification, by checking that the app state is inactive (which is not true when notification is received but not tapped). You just need to update your AppDelegate.m as follows:

image

If you need to run jobs even when user does not tap the notification you might want to add a didReceiveRemoteNotification method with a third parameter userTapped (based on applicationState) in RCTPushNotificationManager.m library. Then you would just have to branch it in the react native lib to fix what happens line 220 in https://github.com/zo0r/react-native-push-notification/blob/master/index.js

All 9 comments

I have the same problem too.
The problem lies on
https://github.com/zo0r/react-native-push-notification/blob/master/index.js
line 220

if the notification is received in background, the userInteraction will always be true

So what is the fix? Is this a duplicate of https://github.com/zo0r/react-native-push-notification/issues/175

I got the same issue when added content-available=1, because without this parameter onNotification doesn't trigger in background, but I need triggering in background. But one more problem appeared with userInteraction always true.

Do somebody have a solution?

+1

+1

+1

From this post I was able to trigger the method onNotification only when user taps on notification, by checking that the app state is inactive (which is not true when notification is received but not tapped). You just need to update your AppDelegate.m as follows:

image

If you need to run jobs even when user does not tap the notification you might want to add a didReceiveRemoteNotification method with a third parameter userTapped (based on applicationState) in RCTPushNotificationManager.m library. Then you would just have to branch it in the react native lib to fix what happens line 220 in https://github.com/zo0r/react-native-push-notification/blob/master/index.js

@colaskirschoff what about the case when the screen in locked. You tap on the notification, then you enter the passcode or faceID. In this case the didReceiveRemoteNotification:inactive will not be called!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings