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端初始化配置
- 确认
Info.plist已添加通知权限及后台模式配置:<key>NSUserNotificationUsageDescription</key> <string>需要发送通知提醒您相关事项</string> <key>UIBackgroundModes</key> <array> <string>remote-notification</string> </array> - 在
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
相关产品推荐
相关产品推荐

