我正在尝试添加以下行,但它给了我一个错误
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
还添加了包.. 但它给出了一个错误,如
Try correcting the name to the name of an existing method, or defining a method named 'onBackgroundMessage'.```
答案 0 :(得分:1)
你用错了,如下使用:
final FirebaseMessaging _auroMessaging = FirebaseMessaging();
//Method to register for FCM Messages
void registerAuroNotifications() async {
//Initialize Firebase
await Firebase.initializeApp();
//Prasad Get User permissions on iOS
getFCMIOSPermission();
// Listen for Messages
this.listenToFCMMessages();
this.getFCMToken();
}
//Method getFCMIOSPermission
void getFCMIOSPermission() {
_auroMessaging.requestNotificationPermissions(const IosNotificationSettings(
sound: true, badge: true, alert: true, provisional: true));
_auroMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("IOS Settings registered: $settings");
});
}
//Method to get FCM Token
void getFCMToken() {
_auroMessaging.getToken().then((token) {
_fcmToken = token;
sendTokenForFCMtoServer(_fcmToken);
print('Token : $token');
});
}
//Method to register and listen to FCM messages
void listenToFCMMessages() {
_auroMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('onMessage : $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('onLaunch : $message');
},
onResume: (Map<String, dynamic> message) async {
print('onResume : $message');
},
onBackgroundMessage: (Map<String, dynamic> message) async {
print('onResume : $message');
},
);
}