App Explain
i'm developing react native reminder app and i want to call function that remind time of the day want to call function once per installation and never call it again when user open the app. just once per installation
using react-native-push-notification PouchDb
try asyncStorage but it's not good solution for this case
function
PushNotification.localNotificationSchedule({
id:notificationId,
message: reminder.name, // (required)
date: new Date(Date.now() diffSeconds),
allowWhileIdle: true,
repeatType:"week",
channelId : "Reminder",
priority:"max",
largeIcon : "logo",
soundName: "remind",
smallIcon : ""
})
CodePudding user response:
You can use your state management tool, such as Redux. Basically, you want to initialize state, for example, isOnboardingDone which will be false in the beginning, and you will set it to true after your function is called. However, you need to save the state in the AsyncStorage after, or in other words, you need to persist it. The alternative to AsyncStorage would be to create a field in one of your database tables, such as profile, and to change it via API call.
CodePudding user response:
There's no perfect solution to this problem.
I usually solve this by canceling the previously scheduled notification and then registering a new one each time on app startup. This ensures that there's only one scheduled notification with the same ID
await PushNotification.cancelLocalNotification('123');
await PushNotification.localNotificationSchedule({
id:'123',
...
})
