react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

local notification not working!!

Open anjumpaul opened this issue 7 years ago • 33 comments

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

}); }

anjumpaul avatar Dec 19 '18 11:12 anjumpaul

same for me

roysG avatar Dec 20 '18 22:12 roysG

Same for me

asantos2 avatar Jan 02 '19 15:01 asantos2

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.

asantos2 avatar Jan 02 '19 20:01 asantos2

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.

twohappy avatar Jan 07 '19 19:01 twohappy

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 avatar Jan 08 '19 19:01 pedrosimao

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

pedrosimao avatar Jan 08 '19 19:01 pedrosimao

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

daaanigm avatar Jan 15 '19 15:01 daaanigm

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

asantos2 avatar Jan 15 '19 16:01 asantos2

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

cuongtranduc avatar Jan 26 '19 17:01 cuongtranduc

Same problem on android devices any help please?

imspikey avatar Jan 27 '19 07:01 imspikey

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

asantos2 avatar Jan 28 '19 21:01 asantos2

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,
});

josephtactica avatar Jan 29 '19 20:01 josephtactica

@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

asantos2 avatar Feb 06 '19 14:02 asantos2

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

Slals avatar Feb 14 '19 02:02 Slals

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!

olegdev avatar Apr 13 '19 13:04 olegdev

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

anwarhamr avatar Apr 16 '19 22:04 anwarhamr

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
});

LiamBCN avatar Apr 29 '19 04:04 LiamBCN

@olegdev did the trick for me.

danielsotopino avatar Apr 30 '19 05:04 danielsotopino

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!

lucas-mds avatar May 15 '19 19:05 lucas-mds

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 avatar May 16 '19 14:05 andrewtremblay-pear