gpt4 book ai didi

flutter - 当应用程序在前台时,永不调用Cloud Messaging的onMessage回调,但是会调用onResume和onLaunch吗?

转载 作者:行者123 更新时间:2023-12-03 03:35:07 26 4
gpt4 key购买 nike

我实现了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模拟器上对此进行测试

最佳答案

所以我仔细查看了文档,发现

Note: When you are debugging on Android, use a device or AVD withGoogle Play services. Otherwise you will not be able to authenticate.


切换到具有Playstore支持的设备后,将调用onMessage回调!

关于flutter - 当应用程序在前台时,永不调用Cloud Messaging的onMessage回调,但是会调用onResume和onLaunch吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61555831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com