You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter iOS端通知接收正常但无法查看日志的问题求助

Flutter iOS端通知接收正常但无法查看日志的问题求助

各位好,我现在碰到了Flutter通知的一个奇怪问题:通知在Android和iOS的所有应用状态(前台、后台、甚至应用被终止时)都能正常接收并显示,但Android端每次触发通知时,控制台都能看到对应的日志输出,可iOS端却完全看不到任何print/debug日志。

我已经确认iOS的通知是能正常收到的,就是日志死活不打印,有没有大佬遇到过类似的情况,或者知道为什么iOS上的日志会消失?求指点,万分感谢!

以下是我处理通知的核心代码:

Future showFlutterNotification(RemoteMessage message) async {
  // await initNotification();
  if (GetPlatform.isAndroid) {
    if (message.data.isEmpty) return;
  }
  final notification = NotificationData.fromJson(message.data);
  String dataTitle = notification.title;
  String dataBody = notification.body;
  String notificationType = "";
  notification.keyValuePairs.forEach((key, value) {
    notificationType = value;
  });

  String notificationTitle = dataTitle.isNotEmpty 
      ? dataTitle 
      : (message.notification?.title ?? "");
  String notificationBody = dataBody.isNotEmpty 
      ? dataBody 
      : (message.notification?.body ?? "");

  print("notificationType---> $notificationTitle");

  flutterLocalNotificationsPlugin.show(
    message.hashCode,
    notificationTitle,
    notificationBody,
    payload: jsonEncode({
      "type": notificationType,
      "click_action": "FLUTTER_NOTIFICATION_CLICK",
      "content_available": true,
      "priority": "high",
      "sound": "default",
    }),
    NotificationDetails(
      android: AndroidNotificationDetails(
        'high_importance_channel',
        'Notifications',
        playSound: true,
        channelDescription: 'This channel is used for important notifications.',
        icon: notificationsIcon,
        priority: Priority.max,
        styleInformation: BigTextStyleInformation(
          contentTitle: notificationTitle,
          notificationBody,
        ),
        importance: Importance.max,
        onlyAlertOnce: true,
      ),
      iOS: DarwinNotificationDetails(
        presentAlert: true,
        presentBadge: true,
        presentSound: true,
        presentBanner: true),
    ),
  );
}

我自己先排查了几个点:

  • iOS的通知权限已经全部开启(弹窗、角标、声音都正常工作)
  • 应用在前台时,iOS的通知回调逻辑是能触发的(因为通知能正常显示),就是日志不打印
  • 尝试过用debugPrint替换print,结果还是一样看不到日志

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 12:23:13