React-native-push-notification: onNotification not called when tapped on local notification iOS

Created on 22 Feb 2019  路  22Comments  路  Source: zo0r/react-native-push-notification

I received a local notification upon some action in iOS, But when I click or tap on local notification, onNotification method does not fired.

But when I tapped on remote push notification coming from react-native-one-signal library, then onNotification function is fired. The issue is only with the local notification clicking.
Is there any conflicts between these two libraries react-native-push-notification and react-native-one-signal.
I am using these:

"@estimote/react-native-proximity": "^0.4.1",
"react": "^16.3.1",
"react-native": "0.55.2",
"react-native-push-notification": "^3.1.2",
"react-native-onesignal": "^3.2.4",

In my main class:

class MainPage extends Component {
constructor(props){
super(props);
new ActionManager(this.notification.bind(this));
}

notification(notification) {
  debugger;
    console.log( 'NOTIFICATION:', notification );
    //If app is in open state show alert
    if(notification.foreground)
    {
      this.props.navigation.navigate('RouteNameTwo')
    }
    // process the notification when it is opened by user interaction
      if(notification.userInteraction){
       this.props.navigation.navigate('RouteNameTwo')
      }

}

This is ActionManager class:

export default class ActionManager extends Component
{
constructor(notification) {
super();
this.configure(notification);
}
configure() {

  PushNotification.configure({
          // (required) Called when a remote or local notification is opened or received
            onNotification: function(notification) {
                console.log( 'NOTIFICATION:', notification );
                notification.finish(PushNotificationIOS.FetchResult.NoData);
            },
          // IOS ONLY (optional): default: all - Permissions to register.
          permissions: {
            alert: true,
            badge: true,
            sound: true
        },
          popInitialNotification: true,
          requestPermissions: true,
      });

}
}

Any help would be highly appreciated.
Thanks

Most helpful comment

Have the same problem. When tap on pushNotification in tray bar my app only wake up from foreground, but onNotification event not fired.
RN 0.59.9, react-native-push-notification": "^3.1.3",
Used this solution.

All 22 comments

@saadmutahar
i have the same issue
have you found a solution?

Got this issue too and I'm not even using react-native-one-signal.

My code worked on:

"react": "^16.0.0-alpha.12",
"react-native": "^0.47.1",
"react-native-push-notification": "^3.0.0",

Switching to this versions made it "break":

"react": "16.6.3",
"react-native": "0.58.5",
"react-native-push-notification": "^3.1.2",

I put break in quotation marks because the documentation clearly says

// (required) Called when a remote or local notification is opened or received

I will try to look into this and traceback.

I downgraded from 3.1.2 to 3.0.0 and my onNotification hooks still don't work.
Gonna have a deep look the next days probably, maybe it's a react-native or iOS12 thing.
Gonna try older OS too...

In the touble shooting section it clearly says:

If a user taps an alert, your app will be started or brought to the foreground and onNotification will be called.

So I guess this is a bug?

I'm working with the 3.1.2.
and works fine maybe I forgot something

@saadmutahar @dtmzr
I don't remember if I added extra configuration but here is my AppDelegate.m

@EdgarXolop your didReceiveRemoteNotification method doesn't match to the react-native documentation but this doesn't fix my problem either.

Can I ask which iOS you're running? Do you test with a simulator or real device?

I tried the iPhone X and 6S simulator with iOS 12.1.
Just downloading iOS 10.3.1 to make sure this didn't break with iOS 12.

@dtmzr to work with the notifications, I always use an iPhone 6s with iOS 12.1.4

@EdgarXolop I always close the app and open the notification then. I don't think that my AppDelegate is the source of this problem. I mean it worked before with the old version of my app.

Also not working for me on iOS 12. My only available device with a lower iOS version is an old one with iOS 9, and on that it still works as expected.

For those who are also using react-native-firebase, turns out a local notification from rnpn also triggers the rnfb event. This might be usable for a workaround but haven't done it yet.

Can we confirm that the given issue occurs on iOS 12 only?

@SchwarzerSchnee I tried it on iOS 10.3.1 with a simulator, didn't work either in my case.

Edit: It worked on that version before.

@EdgarXolop @SchwarzerSchnee There's a conflict between two libraries react-native-push-notfication and react-native-one-signal for only local notification in iOS, when I removed react-native-one-signal, the onNotification function perfectly called upon tap on local notification in iOS.
I tried in iOS 12.

Any solution for this issue? We are using react-native-push-notification and react-native-one-signal

@beisert1 Until now there is no solution for it, as you are using react-native-push-notification and react-native-one-signal both at the same time. The only issue is onNotification not called when tapped on local notification in iOS only.
For me I changed my business logic.

I have been trying to get the onNotification event to fire for 2 days and this is my current working solution.

"react": "^16.8.3",
"react-native": "^0.59.0",
"react-native-push-notification": "^3.1.3",
"react-native-onesignal": "^3.0.3",

-podfile
pod 'OneSignal', '~> 2.5.7' . # (this is the version that was working) (2.10.0 will cause onNotification event to not fire)
pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal'

after that just pod install or pod update.

-RCTOneSignal.h
replace (#import "OneSignal.h") to (#import "OneSignal/OneSignal.h")

-for android error
cd node_modules/react-native-onesignal/android/src/main/java/com/geektime/rnonesignalandroid/ReactNativeOneSignalPackage.java
remove every @Override

and you are good to go. Hope this issue will be solve soon.

Have the same problem. When tap on pushNotification in tray bar my app only wake up from foreground, but onNotification event not fired.
RN 0.59.9, react-native-push-notification": "^3.1.3",
Used this solution.

Any success here?

I have the same problem, but onNotification is never called for me in IOS

Is there any workarounds or fixes? Any help would be any help would be appreciated

I have the same issue, everything works fine on Android though. I don't get it

same here

Hi,
This bug is not related to this library.
Please check your installation of react-native-community/push-notification-ios.
Also the token is the APN one in iOS, not compatible with Firebase.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NiuQiaoling picture NiuQiaoling  路  3Comments

sungjinoh picture sungjinoh  路  3Comments

uendar picture uendar  路  3Comments

atteia picture atteia  路  4Comments

GastonEDiaz picture GastonEDiaz  路  3Comments