React-native-push-notification: local notification not working!!

Created on 19 Dec 2018  路  32Comments  路  Source: zo0r/react-native-push-notification

here is my code,
componentDidMount(){
PushNotification.configure({
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
},
permissions: {
alert: true,
badge: false,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});

PushNotification.localNotification({
/* Android Only Properties */
id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
subText: "This is a subText", // (optional) default: none
color: "red", // (optional) default: system default
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'some_tag', // (optional) add tag to message
group: "group", // (optional) add group to message
ongoing: false, // (optional) set whether this is an "ongoing" notification
priority: "high", // (optional) set notification priority, default: high
visibility: "private", // (optional) set notification visibility, default: private
importance: "high", // (optional) set notification importance, default: high
alwaysFireSound: false, // (optional) will play sound even if phone is on silent or vibrate mode, default: false
volume: 0.5, // (optional) volume of the notification sound. Will only work if "alwaysFireSound" is enabled
soundPath: '', // (optional) local path of a sound, not necessarily within the app

/* iOS and Android properties */
title: "My Notification Title", // (optional)
message: "My Notification Message", // (required)
playSound: false, // (optional) default: true
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
repeatType: 'day', // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more

});
}

Stale

Most helpful comment

i've solved the issue doing the following:

  1. Downgrade to 3.1.1
  2. Run gradle clean
  3. Delete build folders (./android && ./android/app)
  4. Run react-native run-android again

Hope this works for you, at least temporally.

All 32 comments

same for me

Same for me

i've solved the issue doing the following:

  1. Downgrade to 3.1.1
  2. Run gradle clean
  3. Delete build folders (./android && ./android/app)
  4. Run react-native run-android again

Hope this works for you, at least temporally.

i've solved the issue doing the following:

  1. Downgrade to 3.1.1
  2. Run gradle clean
  3. Delete build folders (./android && ./android/app)
  4. Run react-native run-android again

Hope this works for you, at least temporally.

thx!
works for me.

It works for me too.
But now it seems the push notifications are not working, and they were working on the 3.1.2 version.
Any tips on this?
Thanks

Actually, push notifications just worked, but makes the app crash... before going back to the 3.1.1 it didn't crash.

I have the same problem that @pedrosimao . Any update? :(

@pedrosimao @danigm87 are you using react-native-background-job too?

i've solved the issue doing the following:

  1. Downgrade to 3.1.1
  2. Run gradle clean
  3. Delete build folders (./android && ./android/app)
  4. Run react-native run-android again

Hope this works for you, at least temporally.

Works for me too, thank you

Same problem on android devices any help please?

@imspikey give me more information about your problem
Android version, lib version?

I had this same problem. I was using version 3.1.2, downgraded to version 3.1.1 and worked for me.
I'm using Android 9.

PushNotificationAndroid.configure({
  onNotification: notification => {
    console.log(notification);
  },
  requestPermissions: true,
});

PushNotificationAndroid.localNotificationSchedule({
  title,
  message,
  date,
});

@slavikdenis the problem isn't gradle, is the lib, im using gradle 3.2.1 and i don't have any problem.
Downgrade react-native-push-notification to 3.1.1, just modify the version on you package.json, delete node_modules/ and run "npm install" or "yarn install".

Hope this works for you

Does work for me, tries to downgrade gradle to 3.1.1 also the package to 3.1.1, nothing worked. It works on iOS though.

All the permissions are set, it should work...

i've solved the issue doing the following:

  1. Downgrade to 3.1.1
  2. Run gradle clean
  3. Delete build folders (./android && ./android/app)
  4. Run react-native run-android again

Hope this works for you, at least temporally.

It works. Thank you!

Are you getting any messages in your output from Android Studio or xcode?
I was having an issue where the icon would sometimes show in the notifications bar but nothing else. After looking through my logcat I found the below error. Someone, I can't find the link now, mentioned that these are required to work in Android manifest even though the the readme states otherwise...

<meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                     android:value="YOUR NOTIFICATION CHANNEL NAME"/>
 <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
                         android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>

Logcat error:

.../RNPushNotification: failed to send push notification
    java.lang.IllegalArgumentException
        at android.os.Parcel.readException(Parcel.java:2009)
        ...

You will not see a notification if the app is in the foreground on iOS. That is expected behavior

For testing in the foreground try this code

PushNotification.localNotificationSchedule({
  //... You can use all the options from localNotifications
  message: "My Notification Message", // (required)
  date: new Date(Date.now() + (60 * 1000)) // in 60 secs
});

@olegdev did the trick for me.

i've solved the issue doing the following:

  1. Downgrade to 3.1.1
  2. Run gradle clean
  3. Delete build folders (./android && ./android/app)
  4. Run react-native run-android again

Hope this works for you, at least temporally.

Did the trick, thanks!

I was running into this issue as well. For those who can't (or don't want to) delete their./android build folders, check your android manifest.

You might be missing necessary permissions and metadata (listed here in the manual installation page): https://github.com/zo0r/react-native-push-notification#android-manual-installation

@andrewtremblay-pear yes! Could not figure out what was wrong.
localNotif() did fire but no notification showed up.
This part of the readme is not true (anymore ?):

"NOTE: localNotification() works without changes in the application part, while localNotificationSchedule() only works with these changes"

One has to adjust the application part, even for local notifications.

What should I put in channel_name? Any value I want or some specific channel name from somewhere else?

<meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
                     android:value="YOUR NOTIFICATION CHANNEL NAME"/>

Tbh, I am quite new to rn. I just left it untouched, and it worked.

thx @moe11elf. That means anything inside will work just fine. I'd tried it myself and it worked.

For future references - just put anything you want in it. Channel name obviously without spaces.

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.

I have this problem with 3.5.1 version

I am having this problem too, it was working a month ago, but it's not working anymore and I can't seem to find the problem.

@shrynshjain Me too. It stopped working all of a sudden. :(

@slavikdenis the problem isn't gradle, is the lib, im using gradle 3.2.1 and i don't have any problem.
Downgrade react-native-push-notification to 3.1.1, just modify the version on you package.json, delete node_modules/ and run "npm install" or "yarn install".

Hope this works for you

that works for me too, thanks

i've solved the issue doing the following:

1. Downgrade to 3.1.1

2. Run gradle clean

3. Delete build folders (./android && ./android/app)

4. Run react-native run-android again

Hope this works for you, at least temporally.

worked for me thanks

Hi,

Do not downgrade the library!
Old library doesn't work with recent Android.
Please follow the Readme or exemple project!
Create a channel and trigger the notification on this channel.

Regards,

Same issue!
"react-native": "0.63.4",
"react-native-push-notification": "^7.2.1",

Was this page helpful?
0 / 5 - 0 ratings