react-native-push-notification: evaluating RNPushNotification.getInitialNotification is not an object
Hi all,
I have installed React native push Notification and following the installation guide correctly but I faced this error: TypeError: null is not an object (evaluating 'RNPushNotification.getInitialNotification ').
import PushNotification from “react-native-push-notification”; import PushNotificationIOS from “@react-native-community/push-notification-ios”; import {Platform} from “react-native”; NotifService.js:
export default class NotifService {
configure = () => {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token){
console.log("[Notification Service] on register token:", token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: (notification) => {
console.log("[Notification Service] onNotification:", notification);
// process the notification
// required on iOS only (see fetchCompletionHandler docs: https://github.com/react-native-community/react-native-push-notification-ios)
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
senderID: "----",
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
}
}
MyComponent.js:
componentDidMount() {
this.localNotif = new NotifService();
this.localNotif.configure();
}
Any help/Ideas please?!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 29
I solved my issue
npm install react-native-push-notification --save
Yeah tried that too !
Edit : I reset the cache and deleted the build folder and now the error is gone but I am not getting the notification 😐
Edit 2. : I forgot to create a channel and after reading the changelog I did it properly and now it works perfectly and fine !
The possible fix for this issue is
reset the cache and delete the build folder and now the error will be gone
Hello, I have the same error with an android device on an Expo App :
null is not an object (evaluating 'RNPushNotification.getInitialNotification').
Does anyone has already fixed this problem ? Thank you!
this woked for me
npm start – --reset-cache
The package would not be linked to your java file. In your MainApplication.java file add:
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
also add
new ReactNativePushNotificationPackage()
to getPackages method return value so it looks like this :Still not fixed? I am on version 7 and it is returning same error.
I would suggest you to uninstall and re install the app on your device after clearing cache and deleting build folder. I assume this issue is being caused when react native doesn’t recognise it properly.
Build folder’s location :
android/app/build
And you don’t need to manually search for the cache and delete it. Jus run the command
npm start -- --reset-cache
in your project’s directoryEDIT: This is most likely because you changed non hot loaded files when configuring (like manifest, .java files) without relaunching run-android.
Kill everything. Then configure everything as dictated by the github install process. Then start your react service ‘npx react-native start’ then run your android ‘npx react-native run-android’
@tarunkishore2303 Thank you very much!!! That really works!
Wait for a fix or just downgrade. I have
and this works