我在我的Android应用程序中实现了HeadlessJS,当我从Websocket服务器收到通知时,应用程序按预期触发我的任务。 我的下一个任务是将新的传入通知有效负载添加到Redux Store,但任务js文件是这样的,我知道只将组件连接到商店。
目标是在onNotification函数中调度传入的数据并将其保存到redux。如何做?谢谢!
import PushNotifications from 'react-native-push-notification';
module.exports = async (taskData) => {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function (token) {
console.log('TOKEN:', token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
},
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
// senderID: "YOUR GCM SENDER ID",
// 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,
});
PushNotifications.localNotification({
id: taskData.conversation_id, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "Club Message", // (optional)
autoCancel: true, // (optional) default: true
imageUrl: 'https://uri/avatar.jpg',
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: "New message on Attraction App", // (optional) default: none
vibrate: true, // (optional) default: true
vibration: 500, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'message', // (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: taskData.username,
message: 'Message: ' + taskData.message, // (required)
playSound: false, // (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)
// number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
// actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
});
console.log(taskData);
}