Schedule local notifications of React native push notification in react native - react-native

I am using react-native-push-notifications npm library to implement notifications feature in my app. However, I want to schedule the notifications and I am using PushNotification.localNotificationSchedule for doing so. Initially, it was working fine for me yesterday, But somehow it is not working now when I am trying to trigger. I have pasted the code below. Someone could please help me with this.
PushNotification.configure({
onRegister: token => console.log('Token', token),
onNotification: notification => console.log('NOTIFICATION', notification),
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
PushNotification.createChannel({
channelId: 'hello',
channelName: 'my channel',
channelDescription: 'A channel for Notification',
playSound: true,
soundName: 'default',
importance: Importance.HIGH,
vibrate: true,
});
PushNotification.localNotificationSchedule({
channelId: 'hello',
channelName: 'my channel',
autoCancel: true,
bigText: `Time to do ${text}`,
title: `Start doing ${text}!`,
date: new Date(Date.now() + 60 * 1000),
playSound: true,
soundName: 'default',
importance: Importance.HIGH,
vibrate: true,
vibration: 300,
repeatTime: 1,
id: id,
});
LocalNotification(
task?.notId,
task?.date,
task?.start_time,
task?.tname,
);
I have followed the documentation and spent hours on solving issue but couldn't succeeded.

Related

ERROR [Error: notifee.displayNotification(*) 'notification' expected an object value.]

const onDisplayNotification = async () => {
await notifee.displayNotification({
title: 'Notification Title',
body: 'Main body content of the notification',
android: {
channelId,
// color:'#9c27b0',
// backgroundColor:'transparent',
style: {
type: AndroidStyle.BIGTEXT,
text: 'Large volume of text shown in the expanded state',
},
smallIcon: 'ic_launcher', // optional, defaults to 'ic_launcher'.
// pressAction is needed if you want the notification to open the app when pressed
badgeIconType: AndroidBadgeIconType.SMALL,
badge: true, // disable in badges
pressAction: {
id: 'default',
},
},
});
};
above code is an error in notifee.displaynotification in my code.so kindly help this error

Show Notification when app is open, not just when it's closed

I'm working on project using react-native-push-notification my config file is like below:
PushNotification.configure({
onRegister: function (token) {
},
onNotification: function (notification) {
console.log("On Notification",notification)
},
onAction: function (notification) {
console.log("On Notification Action")
},
onRegistrationError: function(err) {
console.error(err.message, err);
},
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
If the app is closed the notification is shown, but if it's opened the notification is not showing, I want to show the notification even if the app is opened.
how to achieve that is this a parameter to add in the configure ?

How do I hide TippyJS when element inside it is clicked?

I have to hide my tippy when an element inside it has been clicked (element is i.e. small images acting as links) but I have not been able to find any usefull scripts that works with my tippy.
I have i.e. tried these without luck:
How to show tooltip on mouseenter and hide on click with Tippy.js
https://github.com/atomiks/tippyjs/issues/437
Can anyone help? :-)
Here is my TippyJS :
tippy('#ReactionBar' + val, {
a11y: true,
role: 'tooltip',
allowHTML: true,
animation: 'perspective-extreme',
appendTo: () => document.body,
arrow: true,
arrowType: 'sharp',
boundary: 'HTMLElement',
content: ReactionBarContent.get(0).outerHTML,
delay: 0,
offset: [0, 5],
duration: [325, 275],
hideOnClick: true,
ignoreAttributes: false,
inertia: false,
interactive: true,
interactiveBorder: 2,
interactiveDebounce: 0,
placement: 'top-end',
popperOptions: {},
showOnCreate: false,
size: 'regular',
target: '',
theme: 'light',
touch: true,
trigger: 'mouseenter focus',
triggerTarget: null,
moveTransition: 'transform 0.2s ease-out',
});
I was facing the same issue and found using the onShown prop and instance.hide() method worked. I found the hideOnClick prop wasn't needed for this.
this.tippy = tippy(this.element, {
// your other props
interactive: true,
trigger: 'click',
triggerTarget: this.triggerTarget,
onShown(instance) {
document.querySelector('[data-tippy-root]').addEventListener('click', event => {
instance.hide();
})
}
})

No channel id passed, notifications may not work. react-native-push-notifications

Error: WARN No channel id passed, notifications may not work.
[LOG] createChannel returned 'false'
How to pass the channel id ?
Here's my code:
export const LocalNotification = () => {
PushNotification.localNotification({
autoCancel: true,
bigText:
'This is local notification demo in React Native app. Only shown, when expanded.',
subText: 'Local Notification Demo',
title: 'Local Notification Title',
message: 'Expand me to see more',
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default',
actions: '["Yes", "No"]'
})
}
const startFunction = async () => {
PushNotification.createChannel(
{
channelId: "channel-id-1",
channelName: "My channel",
channelDescription: "A channel to categorise your notifications",
playSound: false,
soundName: "default",
importance: Importance.HIGH,
vibrate: true,
},
(created) => console.log(`createChannel returned '${created}'`)
);
LocalNotification();
}
PushNotification.createChannel(
{
channelId: "channel-id-1",
channelName: "My channel",
channelDescription: "A channel to categorise your notifications",
playSound: false,
soundName: "default",
vibrate: true,
},
(created) => console.log(`createChannel returned '${created}'`)
);
PushNotification.localNotification({
channelId : "channel-id-1",// this is where you need to add local notification
autoCancel: true,
bigText:
'This is local notification demo in React Native app. Only shown, when expanded.',
subText: 'Local Notification Demo',
title: 'Local Notification Title',
message: 'Expand me to see more',
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default',
actions: '["Yes", "No"]'
})

RNFetchBlob.fs.writeFile how get notification on complete (NOT ALERT MESSAGE)

How to notifiy the user on success the file write.
RNFetchBlob.fs.writeFile(path, Base64Code[1], 'base64')
.then(res => {
console.log(res);
if (res > 0) {
alert('download_success');
} else {
alert('download_failed');
}
});
You can try using a local notification with react-native-push-notification
Here's how you can do it:
first of all, import the library
import PushNotification from 'react-native-push-notification'
and then, the function itself:
RNFetchBlob.fs.writeFile(path, Base64Code[1], 'base64')
.then(res => {
console.log(res);
if (res > 0) {
PushNotification.localNotification({
id: '69',
ticker: "Download sucess!",
autoCancel: true,
vibrate: true,
vibration: 300,
ongoing: false,
priority: "high",
visibility: "private",
importance: "high",
title: "My app name",
message: "Your file has now ben saved!"
});
} else {
PushNotification.localNotification({
id: '69',
ticker: "Download error!",
autoCancel: true,
vibrate: true,
vibration: 300,
ongoing: false,
priority: "high",
visibility: "private",
importance: "high",
title: "My app name",
message: "Errors ocurred while saving the file!"
});
}
});
RNFetchBlob.fs
.writeFile(pathToWrite, data, 'utf8')
.then(() => {
RNFetchBlob.android.addCompleteDownload({
title: 'data.pdf',
description: 'Download complete',
mime: 'application/pdf',
path: pathToWrite,
showNotification: true,
});
console.log(`wrote file ${pathToWrite}`);
})
.catch((error) => console.error(error));