【发布时间】:2021-09-06 16:04:42
【问题描述】:
我使用推送通知设置了我的颤振应用程序,但我不知道以下代码用于什么:
_initiateFcm() async {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print('A bg message just showed up: ${message.messageId}');
}
除了初始化 firebase 应用程序之外,我没有找到将它用于其他任何用途的示例……在我的 main() 方法中已经发生了什么。这样做的目的是什么?什么时候用?
我在实际处理收到的推送通知时拥有这些功能:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {});
但我不会将onBackgroundMessage 用于任何事情...
文档说:
/// Set a message handler function which is called when the app is in the
/// background or terminated.
///
/// This provided handler must be a top-level function and cannot be
/// anonymous otherwise an [ArgumentError] will be thrown.
但是没有人在我检查的任何地方使用这种方法......
【问题讨论】:
标签: firebase flutter dart push-notification