我正在尝试发布“计划的本地通知”,以提醒用户即使在用户不使用该应用程序时也要做某事。我想在React-Native应用程序中做到这一点。
我检查了此处提供的答案,但这些答案使用的是Expo CLI,而不是React Native CLI。 Local Schedule Notification react native React native local notifications 还有一些软件包,如Github上的“ react-native-notifications”和“ react-native-push-notifications”,但我无法从中得到结果。在https://github.com/zo0r/react-native-push-notification和https://github.com/wix/react-native-notifications这里检查 我应该如何发布计划的本地通知?
NotificationsAndroid.localNotification({
title: "Local notification",
body: "This notification was generated by the app!",
extra: "data"
});
答案 0 :(得分:0)
您可以使用: 从“ react-native-push-notification”导入PushNotification;
PushNotification.localNotificationSchedule({ 消息:“通知消息”, date:new Date(Date.now()+ 60 * 1000),// 60秒 });
答案 1 :(得分:0)
您可以在特定时间使用react-native-push-notification
let now = new Date();
now.setDate(now.getDate())
now.setHours(15);
now.setMinutes(58);
now.setMilliseconds(0);
PushNotification.localNotificationSchedule({
//... You can use all the options from localNotifications
message: "My Notification Message", // (required)
repeatType: 'day',
date: new Date(now),
allowWhileIdle: true, // (optional) set notification to work while on doze
});