1

我在带有timer的页面上使用 react-native-push-notification 。如果应用程序在 5 分钟后处于后台,则会通知我时间已过。当我单击通知时,它会转到此页面。但是当我完全关闭应用程序并在 5 分钟后单击通知时,它会转到开始页面。现在的问题是如何让它进入这个页面?

//
let remainingTime = (this.state.minute * 60 + this.state.seconds) * 1000;

let date = new Date(Date.now() + remainingTime);
PushNotification.localNotificationSchedule({
    message: "Message",
    date,
    soundName: "rush"
});
4

1 回答 1

1

当打开或接收到任何通知时,将调用回调onNotification传递带有通知数据的对象。

通知对象示例:

{
    foreground: false, // BOOLEAN: If the notification was received in foreground or not
    userInteraction: false, // BOOLEAN: If the notification was opened by the user from the notification area or not
    message: 'My Notification Message', // STRING: The notification message
    data: {}, // OBJECT: The push data
}

因此,当 onNotification 被触发时,您可以获得数据对象并根据其值编写重定向逻辑。

为了更清楚,您可以在开始屏幕或主文件中使用此代码

var PushNotification = require('react-native-push-notification');

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 );

        // process the notification
   }
});
于 2019-02-26T06:52:18.033 回答