所以我在我的應用程序中有這個「靜音聊天室」功能。 如果聊天室被靜音,從該聊天室的通知數據中包含「靜音= 1」 像下面,如何在通知顯示在後臺之前處理通知?
AnyHashable("aps"): {
"content-available" = 1;
alert = "Android @qwer: Gggggggg";
badge = 8;
sound = default;},
AnyHashable("custom"): {
a = {
comment = 423;
event = 133;
mute = 1;
};
}
,當我收到通知,我決定天氣根據靜音布爾來顯示警報/聲音
它,當我收到時應用程序是在前臺通知工作正常
它是這樣的:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo
guard let data = userInfo["custom"] as? [String: Any] else { return }
guard let additional = data["a"] as? [String: Any] else {
print ("no addi")
return }
let mute = additional["mute"] as? NSNumber
if mute == 1 {
completionHandler([ .badge])
} else if mute == 0 {
completionHandler([.alert, .badge, .sound])
}}
但事情變得棘手,當應用程序在後臺,
當我收到當應用程序在後臺的通知,
這種方法
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
被調用時,它會立即顯示通知提醒。
所以我怎麼想靜音聊天室(不顯示警報和靜音),當應用程序在後臺...
非常感謝!
你不應該設置在推警報或音鍵,但在應對無聲推 – Paulw11