当应用程序处于后台时,didReceiveRemoteNotification不会与Firebase一起调用 [英] When app is in background didReceiveRemoteNotification not called with Firebase

查看:115
本文介绍了当应用程序处于后台时,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
}
}

请参阅表1的HTTP服务器协议文档
$ b


在iOS上,使用此字段来表示APN
有效内容中的可用内容。当发送通知或消息并将其设置为
true时,会激活非活动客户端应用程序。在Android上,数据消息默认唤醒
应用程序。在Chrome上,目前不支持。



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:

On iOS, use this field to represent content-available in the APNs payload. When a notification or message is sent and this is set to true, an inactive client app is awoken. On Android, data messages wake the app by default. On Chrome, currently not supported.

这篇关于当应用程序处于后台时,didReceiveRemoteNotification不会与Firebase一起调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆