应用程序失效时Flutter中的Firebase推送通知



当应用程序KILLED时,我在处理Firebase推送通知时遇到问题。发生了什么:首先,推送通知应该是这样工作的。点击时,会重定向到移动类型作业或事件类型作业。

  • 当应用程序处于背景模式时,推送通知会显示出来,并且它重定向到它应该重定向的页面
  • 当应用程序KILLED时,推送通知仍会显示,但当你点击它们时,你不会被重定向,你只是在打开应用程序

Future initialize() async {
await getConnectivity();
if (hasInternet) {
try {
await configurePushNotificationHandlers();
} catch (e) {
hasApiConnection = false;
}
}
}

Future configurePushNotificationHandlers() async {
await navigationService.navigateReplacementWithParams(ErrorPage());
await _firebaseMessaging.requestPermission(
alert: true,
badge: true,
provisional: false,
sound: true,
);
String fbToken = await _firebaseMessaging.getToken();
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
if (message.data != null && message.data.containsKey('showInPageNotification')) {
numberOfNotifications++;
}
notifyListeners();
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
print('A new onMessageOpenedApp event was published!');
if (message.data != null && message.data.containsKey('job_id')) {
String jobId = message.data['job_id'];
String jobType = message.data['job_type'];
jobType = jobType.toLowerCase();
if (jobType == 'move') {
await goToJobDetail(jobId);
} else {
await goToEventDetail(jobId);
}
}
});

有人知道为什么会发生这种事吗?推送通知工作正常,这是当前ISSUE的重定向。谢谢

使用FirebaseMessaging.instance.getInitialMessage((方法获取消息

如果应用程序关闭/终止

FirebaseMessaging.instance
.getInitialMessage()
.then((RemoteMessage message) {
print("FirebaseMessaging.getInitialMessage $message");
});

试试这个,让我知道

最新更新