我试图使用这个@react本机-社区/推送-通知-ios包在IOS中实现本地通知。
我正确地跟踪了所有的文件。尽管如此,LocalNotification仍然不起作用。
这是我的环境配置:- react-native:0.61.4 - @react-native-community/push-notification-ios --save:1.0.5
我做了以下几件事
npm i @react-native-community/push-notification-ios --savecd ios && pod installAppDelegate.m更新这里import PushNotificationIOS from "@react-native-community/push-notification-ios";
.
.
.
componentDidMount(){
PushNotificationIOS.addEventListener('localNotification', this._onNotification);
PushNotificationIOS.requestPermissions();
PushNotificationIOS.presentLocalNotification({
alertBody: 'Test Notification'
});
}
_onNotification(notification) {
console.log(notification._alert);
}
.
.
.console.log,但没有得到任何本地通知。发布于 2020-02-20 08:41:01
那么,当应用程序在前台运行时,您将无法看到通知。您可以调用本地调度函数和快速隐藏应用程序的背景,然后您将看到通知。
源代码:-
PushNotificationIOS.localNotificationSchedule({
message: "Local push notification", //mandatory
number: 1,
date: new Date(Date.now() + (5 * 1000)) // Schedule in 5 secs
});https://stackoverflow.com/questions/60314995
复制相似问题