Flutter中的一个信号静默通知

问题描述 投票:0回答:1

我在两个平台上都实施了静默通知。根据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

ios flutter onesignal
1个回答
0
投票

我没有找到直接检索收到的通知的方法。因此,我创建了一个到本机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)
                            }

                    }}
    }

}

© www.soinside.com 2019 - 2024. All rights reserved.