ios - Flutter 中的 One Signal 静默通知
问题描述
我为两个平台实现了静默通知。根据 OneSignal 的文档,在 Android 上我必须添加一个类 NotificationServiceExtender 而在 IOS 中我只需要从 REST API content_available:true 发送
正常通知在两个平台上都有效,但 IOS 中的静默通知没有触发:
OneSignal.shared
.setNotificationReceivedHandler((OSNotification notification) async {
print(notification);
}
在 AppDelegate 中,我测试了是否从 OneSignal 返回任何内容,并且似乎正在返回数据:
override func application(_ application: UIApplication, didReceiveRemoteNotification
userInfo: [AnyHashable : Any]) {
print(userInfo)
}
我不知道 OneSignal 的 FLutter 上是否有另一种可以触发的方法,或者我应该建立一个到 IOS 的通道并检索数据。这样可能会变得复杂。
另外我必须提到,静默通知正在 Android 设备上运行。
包裹: onesignal_flutter: ^2.0.0
解决方案
我没有找到直接检索收到的通知的方法。因此,我创建了一个到 Native IOS 的 Flutter Channel,我可以从中检索数据。
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
var notificationData:NSMutableDictionary
var isAppInFocus: Bool = false
if let custom = userInfo["custom"] as? NSDictionary {
if let data = custom["a"] as? NSDictionary {
notificationData = data.mutableCopy() as! NSMutableDictionary
if(data["category"] as? String == "MESSAGESTATUS"){
notificationChannel.invokeMethod("getSilentLastSeenMessage", arguments: notificationData)
}
}}
}
}
推荐阅读
- html - 如何在 Angular 中显示列表
- php - 对特定列求和并在 mysql 上显示其他列
- http - Http/2 中的连接将保持多长时间
- python - AttributeError:模块“sklearn.mixture”没有属性“GMM”
- python - 将python程序更改为python tkinter
- odoo - 管理员用户的常规设置中的权限被拒绝更改 - Odoo 10
- javascript - 使用对象和数组的 JS 登录/注册
- spring-boot - 在 Spring Boot 中使用数据库 H2 进行测试
- oop - Fortran 中两个不同声明之间的差异
- laravel - 卡住一对一的关系 laravel