react-native-push-notification: undefined is not an object (evaluating 'RNPushNotification.presentLocalNotification')

Hello,

I setup react-native-push-notification according the Readme, but when i use the localNotification like this:

var PushNotification = require('react-native-push-notification');

PushNotification.localNotification({
   message: 'My notification message'
});

I have this error:

undefined is not an object (evaluating 'RNPushNotification.presentLocalNotification')

Have you some idea about this ?

My react native version: 0.36

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 28 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Apparently i have the same problem, with a different message: undefined is not an object (evaluating RNPushNotification.getInitialNotification)

Any ideas?

I have the same issue

i had the same issue. Fixed after running react-native run-android in the terminal.

Always the same 😕 I just recheck readme and trouble shooting guide, i do react-native link, and in settings.gradle :

include ':react-native-push-notification'
project(':react-native-push-notification').projectDir = file('../node_modules/react-native-push-notification/android')

in build.gradle:

    compile project(':react-native-push-notification')
    compile ('com.google.android.gms:play-services-gcm:+') {
        force = true;
    }

In the MainApplication.java the package is imported

import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;

and i verified that package has been added in react package list

  protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new ReactNativePushNotificationPackage()
      );
    }

Also, i run the application in my physical devise and i sure that this package are correctly linked.

Do you think it is surely a version issue ?

The issue I faced- “undefined is not an object (evaluating RNPushNotification.getInitialNotification)”. The reason- I was trying to integrate the library while using expo for running project which is not supported. You will have to eject your project using “react-native init”. Doing so worked for me. Strange thing is no one has mentioned that it will not work with expo as a lot of people use expo for development of their mobile apps.

After running react-native link, I received this error:

Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
        at com.android.dx.command.dexer.Main.run(Main.java:277)
        at com.android.dx.command.dexer.Main.main(Main.java:245)
        at com.android.dx.command.Main.main(Main.java:106)
    
:app:transformClassesWithDexForDebug FAILED

Update: I had to add the following into my build.gradle file:

compile ("com.google.android.gms:play-services-base:10.0.1") {
        force = true;
    }
    compile ("com.google.android.gms:play-services-maps:10.0.1") {
        force = true;
    }
    compile ("com.google.android.gms:play-services-gcm:10.0.1") {
        force = true;
    }
    compile ('com.google.firebase:firebase-core:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-messaging:10.0.1') {
        force = true;
        }

but now it gives me the same error: undefined is not an object (evaluating RNPushNotification.getInitialNotification)

Doesn’t seem like this issue should be closed…

Can confirm running react-native run-android after react-native link command solves the issue

I was having this problem just a minute ago. i did react-native link and the output said the notification lib was linked… but I needed to modify MainActivity anyway.

Make sure you import it like this import PushNotification from 'react-native-push-notifications'; (no brackets). Or whatever the OneSignal class is (I’m not using it for OneSignal, so I’m not sure how that works in this library). Also just follow the setup documentation slowly and carefully, if you follow all of the steps it will work. If it still doesn’t work, just post your manifest here and your JavaScript and someone will identify the issue.

Just had the same issue, it was because react-native link did not add new ReactNativePushNotificationPackage() in MainApplication.java, adding it manually made it work.

sounds like you’ve not linked you’re project correctly. Please recheck the readme and the trouble shooting guide.