Swift Group 推送通知
Posted
技术标签:
【中文标题】Swift Group 推送通知【英文标题】:Swift Group push notifications 【发布时间】:2019-07-15 16:00:23 【问题描述】:我有社交网络应用,并且...我想知道这个应用是否可以在锁定屏幕上对通知进行分组。
我的远程服务器向 APNs 发送通知,然后我通过设备令牌接收它。有没有办法按应用程序分组通知?我在 medium 上找到了代码,但我不知道如何实现它。
https://medium.com/swift-india/lets-take-quick-dive-in-grouped-notifications-5d41af9d6463
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
//over here add condition if same user has opened chat and notification is also from same user dont show these
let extraPayLoad = (notification.request.content.userInfo["extraPayLoad"] as? [AnyHashable : Any])
if extraPayLoad!["custom"] != nil
let info_string = extraPayLoad!["custom"] as? String
let objectData: Data? = info_string?.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
var json: [AnyHashable : Any]? = nil
if let aData = objectData
json = try! JSONSerialization.jsonObject(with: aData, options: .mutableContainers) as? [AnyHashable : Any]
if json?["sender_id"] != nil
if let aKey = json?["sender_id"]
print("sender_id : \(aKey)")
if(json?["code"] as? Int ?? 0 != 1003 && json?["code"] as? Int ?? 0 != 1004)
let unread_count_dict:[String: Bool] = ["unread_count": true]
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showNotificationView"), object: nil, userInfo: unread_count_dict)
if (UserDefaults.standard.value(forKey: "_targetId") as? String ?? "0") == "\((json?["sender_id"] as? Int ?? -1))"
//
// NotificationCenter.default.post(name: NSNotification.Name("GetAllConversationsList"), object: self)
//return
if (UserDefaults.standard.value(forKey: "_groupId") as? String ?? "0") == "\((json?["group_id"] as? Int ?? -1))"
// NotificationCenter.default.post(name: NSNotification.Name("GetAllConversationsList"), object: self)
//return
completionHandler([.sound, .alert, .badge])
【问题讨论】:
【参考方案1】:如果有人需要回答……
只需将带有任何标识符的 thread-id 字段添加到您的服务器,push not 将自动按此 ID 分组...)
【讨论】:
以上是关于Swift Group 推送通知的主要内容,如果未能解决你的问题,请参考以下文章