本文介绍了当应用程序处于后台时,didReceiveRemoteNotification不会与Firebase一起调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Firebase我发送这个JSON:
{
data:{
},
priority:high,
to:xxxxx,
content-available:true,
notification:{
body:HI!,
title:FCM Message,
badge:1,
sound:Default
}
但是 didReceiveRemoteNotification:fetchCompletionHandler
当应用程序在后台时不会被调用。
启用后台模式 - 从功能的远程通知。建议?
解决方案
内容可用的键/值不正确。关键是 content_available
(下划线,而不是短划线),值是一个布尔值,而不是字符串:
{
data:{
},
priority:high,
to:xxxxx,
content_available:true,//< = CHANGED
通知:{
body:HI!,
title:FCM Message,
badge:1,
sound:Default
}
}
请参阅:
$ b
With Firebase I send this JSON:
{
"data": {
},
"priority": "high",
"to": "xxxxx",
"content-available": "true",
"notification": {
"body": "HI!",
"title": "FCM Message",
"badge": 1,
"sound": "Default"
}
}
But didReceiveRemoteNotification:fetchCompletionHandler
is not called when app is in background.
I enable background Modes - Remote notifications from capabilities.
Any suggestions?
解决方案
Your key/value for content-available is incorrect. The key is content_available
(underscore, not dash) and the value is a boolean, not string:
{
"data": {
},
"priority": "high",
"to": "xxxxx",
"content_available": true, // <= CHANGED
"notification": {
"body": "HI!",
"title": "FCM Message",
"badge": 1,
"sound": "Default"
}
}
See Table 1 of the HTTP Server Protocol document:
这篇关于当应用程序处于后台时,didReceiveRemoteNotification不会与Firebase一起调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!