zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.76k stars 2.05k forks source link

local notification not working!! #968

Closed anjumpaul closed 4 years ago

anjumpaul commented 5 years ago

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

}); }

roysG commented 5 years ago

same for me

asantos2 commented 5 years ago

Same for me

asantos2 commented 5 years ago

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.

twohappy commented 5 years ago

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.

pedrosimao commented 5 years ago

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

pedrosimao commented 5 years ago

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

daaanigm commented 5 years ago

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

asantos2 commented 5 years ago

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

cuongtranduc commented 5 years ago

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

imspikey commented 5 years ago

Same problem on android devices any help please?

asantos2 commented 5 years ago

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

josephtactica commented 5 years ago

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,
});
asantos2 commented 5 years ago

@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

Slals commented 5 years ago

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...

olegdev commented 5 years ago

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!

anwarhamr commented 5 years ago

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)
        ...
DevJett commented 5 years ago

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
});
danielsotopino commented 5 years ago

@olegdev did the trick for me.

lucas-mds commented 5 years ago

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!

andrewtremblay-pear commented 5 years ago

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

moe11elf commented 5 years ago

@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.

keeprock commented 5 years ago

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"/>
moe11elf commented 5 years ago

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

keeprock commented 5 years ago

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.

github-actions[bot] commented 4 years ago

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.

hadpro24 commented 4 years ago

I have this problem with 3.5.1 version

shrynshjn commented 4 years ago

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.

vysakh0 commented 4 years ago

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

BLemine commented 3 years ago

@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

sachin3018 commented 3 years ago

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

Dallas62 commented 3 years ago

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,

ShakeelAhmad-dev commented 3 years ago

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

kegacbongdem commented 3 years ago

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