gpt4 book ai didi

ios - 静默推送通知仍会正常弹出

转载 作者:行者123 更新时间:2023-11-28 14:25:54 25 4
gpt4 key购买 nike

我正在尝试设置静默推送通知,但遇到了这个问题。我发送到 APNs 的 JSON 是:

{
"aps": {
"alert": "test",
"badge": 0,
"content-available": 1
}
}

委托(delegate)方法是:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
var pushData = userInfo["aps"] as? [AnyHashable : Any];
if pushData?["content-available"] as? Int == 1 {
NSLog("received silent notification")
completionHandler(.noData)
} else {
NSLog("received notification")
completionHandler(.newData)
}
}

当后端发送推送通知时,我的应用程序处于后台。 XCode 显示“收到静默通知”,但此通知仍正常弹出。你能告诉我,我在做什么错了吗?这可能不应该发生,对吧?

项目设置为在“后台模式”中选中“远程通知”。

最佳答案

静默推送通知的正确 json 负载应如下所示

{
"aps" = {
"content-available" : 1,
"sound" : ""
};
// add custom key-value pairs
}

关于ios - 静默推送通知仍会正常弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51572524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com