所以我在我的应用程序中有这个“静音聊天室”功能。 如果聊天室被静音,从该聊天室的通知数据中包含“静音= 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