Plugin.Firebase.CloudMessaging推送Campaign“Opens”统计不更新问题
.NET MAUI FCM 通知点击后Firebase Campaign「Opens」统计不更新的解决方案
Android 端修复步骤
- 修正通知Intent配置
自定义NotificationBuilderProvider时,必须使用FCM提供的Intent确保追踪参数被正确传递,否则Firebase无法识别通知打开事件。修改代码如下:
FirebaseCloudMessagingImplementation.NotificationBuilderProvider = notification => { // 获取FCM内置的通知Intent,包含统计所需参数 var intent = FirebaseCloudMessagingImplementation.CreateNotificationIntent(this, notification); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable); return new NotificationCompat.Builder(this, channelId) .SetSmallIcon(ResourceConstant.Mipmap.appicon_round) .SetContentTitle(notification.Title) .SetContentText(notification.Body) .SetAutoCancel(true) .SetContentIntent(pendingIntent); // 绑定正确的PendingIntent };
同时确保MainActivity的LaunchMode不是singleInstance或singleTask,这类启动模式会干扰Intent参数传递。
- 手动上报打开事件
如果自定义Intent仍无法触发自动上报,可在MainActivity中手动处理Intent并上报:
protected override void OnNewIntent(Intent intent) { base.OnNewIntent(intent); if (intent.Extras != null && intent.Extras.ContainsKey("google.message_id")) { // 手动通知Firebase用户打开了通知 FirebaseCloudMessagingImplementation.NotifyNotificationOpened(intent.Extras); } }
iOS 端修复步骤
- 完善AppDelegate的通知处理逻辑
在AppDelegate.cs中添加以下代码,确保通知点击事件被正确上报给Firebase:
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) { FirebaseCloudMessagingImplementation.DidReceiveRemoteNotification(userInfo); completionHandler(UIBackgroundFetchResult.NewData); } public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { FirebaseCloudMessagingImplementation.DidReceiveNotificationResponse(response); completionHandler(); }
同时确认Info.plist中已开启Remote notifications后台模式,并且应用已获取远程通知权限。
通用排查要点
- 确保使用的
Plugin.Firebase.CloudMessaging是最新版本,旧版本可能存在统计上报的bug。 - 测试时必须通过Firebase控制台的Campaign发送通知,普通单设备推送不会计入Campaign的Opens统计。
- 确认设备处于联网状态,通知打开事件需要联网才能上报,离线状态下会延迟到联网后发送。
内容的提问来源于stack exchange,提问作者CrazyEight
相关产品推荐
相关产品推荐

