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

Flutter集成Awesome Notification后iOS推送通知点击抛出异常求助

解决Flutter Awesome Notifications iOS点击通知抛出异常的问题

这个报错的核心原因是iOS端接收到的通知内容未包含Awesome Notifications组件要求的专属标识信息,导致组件无法识别并处理点击事件。以下是具体解决步骤:

  • 统一用组件API构建通知
    无论本地还是远程通知,必须通过AwesomeNotifications提供的方法生成,确保通知数据自带组件所需元数据。示例本地通知构建代码:

    await AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: 1,
        channelKey: 'basic_channel',
        title: '测试通知',
        body: '点击查看详情',
      ),
    );
    
  • 检查iOS端初始化配置

    1. 确认Info.plist已添加通知权限及后台模式配置:
      <key>NSUserNotificationUsageDescription</key>
      <string>需要发送通知提醒您相关事项</string>
      <key>UIBackgroundModes</key>
      <array>
        <string>remote-notification</string>
      </array>
      
    2. 在AppDelegate.swift中正确初始化组件:
      import UIKit
      import Flutter
      import AwesomeNotifications
      
      @UIApplicationMain
      @objc class AppDelegate: FlutterAppDelegate {
        override func application(
          _ application: UIApplication,
          didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
        ) -> Bool {
          AwesomeNotifications().initialize(nil, debug: true)
          GeneratedPluginRegistrant.register(with: self)
          return super.application(application, didFinishLaunchingWithOptions: launchOptions)
        }
      }
      
  • 注册通知点击监听器
    在Flutter侧注册回调,确保组件能捕获并处理点击事件:

    AwesomeNotifications().actionStream.listen((receivedNotification) {
      // 自定义点击后的处理逻辑
      print('通知已点击:${receivedNotification.content.title}');
    });
    
  • 规范远程通知Payload格式
    若使用APNs推送远程通知,需在payload中添加awesome字段,示例格式:

    {
      "aps": {
        "alert": {
          "title": "远程通知",
          "body": "这是一条测试通知"
        }
      },
      "awesome": {
        "content": {
          "id": 2,
          "channelKey": "basic_channel"
        }
      }
    }
    

内容的提问来源于stack exchange,提问作者user1068810

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 00:52:04