首页 > 解决方案 > Flutter IOS BackgroundHandler不工作

问题描述

当数据推送消息到达时,我想要做一个后台处理程序(保存在我的 firebase DB 上)。它在 Android 的后台和前台都可以正常工作,但在 IOS 中,当推送通知接收前台工作正常(当应用程序打开时)但在后台(应用程序关闭)不工作时。

void main() async {

await Firebase.initializeApp();

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message whilst in the foreground!');
print('Message data: ${message.data}');

if (message.notification != null) {
  print('Message also contained a notification: ${message.notification}');
}
});

runApp(MyApp());

}

Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print('trigger........');
}

标签: iosfirebaseflutterpush-notification

解决方案


推荐阅读