我实现了Firebase云消息传递,并遵循了以下教程https://www.youtube.com/watch?time_continue=304&v=2TSm2YGBT1s&feature=emb_logo。而且我大部分时间都在使用它。每当应用程序在后台或关闭时,我都会收到通知,它将打开应用程序并执行onResume或onLaunch回调。
但是我似乎无法使onMessage回调起作用。每当应用程序在前台并且我发送通知时,不会调用onMessage吗?我将以下日志发送到控制台
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;
}
}
我正在使用Pixel 3XL在Android模拟器上对此进行测试
答案 0 :(得分:1)
所以我仔细查看了文档并发现了
注意:在Android上调试时,请在以下设备上使用设备或AVD: Google Play服务。否则,您将无法进行身份验证。
切换到具有Playstore支持的设备后,将调用onMessage回调!