Flutter 当应用程序位于前台时,云消息onMessage回调不会被调用,但onResume和onLaunch会被调用吗?
我实现了firebase云消息传递,并遵循了以下教程。我让它大部分时间都在工作。每当应用程序在后台或关闭时,我都会收到一个通知,它将打开应用程序并在Resume或onLaunch上执行回调 但我似乎无法让onMessage回调正常工作。每当应用程序在前台,我发送通知时,不会调用onMessage?我将以下日志保存到我的控制台Flutter 当应用程序位于前台时,云消息onMessage回调不会被调用,但onResume和onLaunch会被调用吗?,flutter,dart,firebase-cloud-messaging,Flutter,Dart,Firebase Cloud Messaging,我实现了firebase云消息传递,并遵循了以下教程。我让它大部分时间都在工作。每当应用程序在后台或关闭时,我都会收到一个通知,它将打开应用程序并在Resume或onLaunch上执行回调 但我似乎无法让onMessage回调正常工作。每当应用程序在前台,我发送通知时,不会调用onMessage?我将以下日志保存到我的控制台 E/FlutterFcmService(18141): Fatal: failed to find callback W/FirebaseMessaging(18141):
E/FlutterFcmService(18141): Fatal: failed to find callback
W/FirebaseMessaging(18141): Unable to log event: analytics library is missing
W/FirebaseMessaging(18141): Unable to log event: analytics library is missing
我也没有看到有人打电话给onBackgroundMessage
通知服务
class CloudMessagingService extends NotificationService
{
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
CloudMessagingService()
{
if(Platform.isIOS)
firebaseMessaging.requestNotificationPermissions(IosNotificationSettings());
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('I have a cloud messaging message yay');
print('onMessage: $message');
},
onBackgroundMessage: (Map<String, dynamic> message) async {
print('onBackgroundMessage: $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('onLaunch: $message');
},
onResume: (Map<String, dynamic> message) async {
print('onResume: $message');
},
);
}
Future<void> sendNotificationToGroup(GroupModel group, NotificationType type)
{
print('Send ${type.valueString} notification to ${group.id}');
return null;
}
}
class CloudMessagingService扩展了NotificationService
{
最终FirebaseMessaging FirebaseMessaging=FirebaseMessaging();
CloudMessagingService()
{
if(Platform.isIOS)
firebaseMessaging.requestNotificationPermissions(IONotificationSettings());
firebaseMessaging.configure(
onMessage:(映射消息)异步{
打印(“我有一条云消息耶”);
打印('onMessage:$message');
},
onBackgroundMessage:(映射消息)异步{
打印('onBackgroundMessage:$message');
},
onLaunch:(映射消息)异步{
打印('onLaunch:$message');
},
onResume:(映射消息)异步{
打印('onResume:$message');
},
);
}
Future sendNotificationToGroup(GroupModel组,NotificationType类型)
{
打印('Send${type.valueString}通知${group.id}');
返回null;
}
}
我正在android模拟器上使用Pixel 3XL进行测试,所以我仔细查看了文档,发现 注意:在Android上调试时,请使用带有 谷歌播放服务。否则,您将无法进行身份验证
切换到支持playstore的设备后,调用了onMessage回调 谢谢。你救了我。