当用户收到通知时,如何将React Native(Expo)应用带到前景
我已经设置 expo通知在后台执行任务,但我的问题是,如果没有用户首先按通知,我如何将应用程序在收到通知后的前景?
这样的事情:
import * as Notifications from "expo-notifications";
import * as TaskManager from "expo-task-manager";
const BACKGROUND_NOTIFICATION_TASK = "BACKGROUND-NOTIFICATION-TASK";
TaskManager.defineTask(
BACKGROUND_NOTIFICATION_TASK,
({ data, error, executionInfo }) => {
console.log("Received a notification in the background!");
// Bring the app to the foreground
}
);
Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);
I have set up expo notification wherein my app listens to incoming notifications and can execute tasks in the background but my question is how do I bring the app to the foreground upon receiving a notification without the user pressing on the notification first?
Something like this:
import * as Notifications from "expo-notifications";
import * as TaskManager from "expo-task-manager";
const BACKGROUND_NOTIFICATION_TASK = "BACKGROUND-NOTIFICATION-TASK";
TaskManager.defineTask(
BACKGROUND_NOTIFICATION_TASK,
({ data, error, executionInfo }) => {
console.log("Received a notification in the background!");
// Bring the app to the foreground
}
);
Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的最接近的事情是创建本地通知,并鼓励用户按通知将应用程序放在前景上。但是,Android或iOS都无法进行确切的问题。
The closest thing that you can do, is to create a local notification and encourage the user to press the notification to put the app to the foreground. But the exact thing you are asking is not possible with Android or either with iOS.