在这件事上被困了好几天。所以,我使用这个包来实现本地推送通知:
https://github.com/zo0r/react-native-push-notification
我可以像这样获得本地计划通知:
PushNotification.localNotificationSchedule({
date: new Date(Date.now() + 30 * 1000), // in 30 secs
/* Android Only Properties */
//id: ''+this.lastId, // (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: "blue", // (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
/* iOS only properties */
alertAction: "view", // (optional) default: view
category: null, // (optional) default: null
userInfo: null, // (optional) default: null (object containing additional notification data)
/* iOS and Android properties */
title: "Scheduled Notification", // (optional)
message: "My Notification Message", // (required)
playSound: true, // (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)
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
foreground: false, // BOOLEAN: If the notification was received in foreground or not
userInteraction: true, // BOOLEAN: If the notification was opened by the user from the notification area or not
data: { type: "test" } // OBJECT: The push data
});
我想在用户点击通知和应用程序打开时调用一个函数。为了实现以下目标,我在我的pp.js中这样做了:
async componentDidMount() {
PushNotification.configure({
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log("NOTIFICATION:", notification);
},
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true
});
}
但是,onNotification
函数不会被调用。
我已经回答了以下几个问题,但是运气不好。
在通知上的本机消息推送不触发
React Native Push Notification onNotification回调不一致
Android onNotification从未在react本机推送通知中调用
我还提出了一个关于Github的问题。
可能的解决方案是什么?
对于那些寻求解决方案的人,我在我的应用程序中做了类似的事情。js的componentDidMount
方法:
PushNotification.configure({
// (required) Called when a remote or local notification is opened or received
onNotification: notification => {
console.log(notification);
if (notification.action === "Take") {
//do something here
} else if (notification.action === "Skip") {
//do something here
} else if (notification.action === "Snooze") {
//do something here
}
},
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true
});
我有一个React原生应用程序(在iOS上测试),正在尝试合并推送通知。我正在使用以下模块:https://www.npmjs.com/package/react-native-firebase-push-notifications. 我尝试运行示例应用程序代码,并能够获得(1)消息令牌和(2)从我的设备成功获得权限。 我正在尝试从Firebase发送测试通知,并且正在使用我设备的令牌。但是,触发
所以我尝试接收推送通知从Firebase和react-native-push-notifications.react本机推送通知在android它的工作完美。 我的问题只出现在IO上。我已经按照push-cendation-ios安装了,但没有结果。 包裹json: appDelegate。m: appDelegate。h: info.plist: 在应用程序标识符上,我已被选中并创建推送通知 生
我已经检查了react native onesignal github README,似乎获得通知的唯一方法是通过onNotificationOpen()回调打开。 他们的文件表明: 当打开或接收到任何通知时,调用回调传递带有通知数据的对象。 但是,显然不起作用。 有没有办法在不打开推送通知或启用应用内警报通知的情况下获取通知?
首先,我想声明我一直在研究推送通知和web通知之间的关系,但我有点困惑。 我从这里读到PWAs的推送通知在Safari上的iOS(iPhone)不起作用:从PWA向iOS发送推送通知 然而,如果iPhone用户使用的是Chrome,这是否意味着它们可以工作呢?或者推送通知在任何浏览器上对iPhone中的PWAs都不起作用? 这就把我带到了web通知。web通知在后台对PWAs起作用吗?我的问题是w
我使用firebase_消息和Flatter_local_通知包,目前我可以在应用程序处于后台时,在用户点击通知时获取通知数据。当应用程序位于前台时,我如何收听点击事件。
这是舱单 这是我的注册令牌类 这是我的Firebase服务类