Firebase FCM消息支持tag for Android,这会导致新的通知用具有相同标签的旧通知替换之前的通知。有没有办法对ios做同样的事情?
此answer建议在数据有效负载中使用线程id。但它对我不起作用。
发布于 2018-10-11 03:28:51
旧版FCM HTTP服务器协议中没有thread-id FCM有效负载密钥。解决方法是使用iOS通知服务扩展。在FCM数据负载中将分组标识符作为"thread-id“键发送,并让服务扩展读取"thread-id”键并将其设置为通知内容的threadIdentifier属性。
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
let userInfo: [AnyHashable : Any] = (bestAttemptContent?.userInfo)!
if let apsInfo = userInfo["aps"] as? [AnyHashable: Any], let bestAttemptContent = bestAttemptContent {
//add thread-id to group notification.
let patientId = userInfo["thread-id"] as! String
bestAttemptContent.threadIdentifier = patientId
contentHandler(bestAttemptContent)
}
}
}https://stackoverflow.com/questions/49758268
复制相似问题