iOS应用未收到来自Firebase的后台推送通知 [英] iOS app doesn't receive background push notifications from Firebase

查看:396
本文介绍了iOS应用未收到来自Firebase的后台推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使推送通知在我正在使用的Cordova应用程序中工作.它们可以在Android应用程序中完美运行,而在iOS应用程序处于前台时则可以完美运行,但是当应用程序在后台或终止时,我不会收到任何通知.

I'm trying to get push notifications working in a Cordova app I'm working on. They work perfectly in the Android app and they work perfectly in the iOS app when it's in the foreground, but I don't receive any notifications when the app is in the background or terminated.

我启用了推送通知"和背景模式-远程通知"功能:

I have the "Push Notifications" and "Background Modes - Remote notifications" capabilities enabled:

我100%确定服务器具有设备令牌(因为推送通知在前台工作,并且我可以在数据库中看到它).

And I'm 100% sure the server has the device token (since push notifications are working in the foreground, and I can see it in the database).

这就是我使用 firebase-admin节点模块发送推送通知的方式:

await firebase.messaging().send({
  token: userDeviceToken,
  data: {foo: 'bar'},
  notification: {
    title: 'This is a notification title',
    body: 'This is a notification body',
  },
});

我想念什么?

如果我在收到通知后启动了应用程序或将其置于前台,则它的行为就好像收到了应用程序内通知.即使我在发送通知后等待了几分钟才启动应用程序,也会发生这种情况.

If I launch the app or bring it to the foreground after it was supposed to receive a notification, it acts like it received an in-app notification. This happens even if I wait several minutes after the notification was sent before launching the app.

推荐答案

检查前台在应用程序中收到的有效负载结构.通常,它与Android不同. iOS有效负载结构应为:

Check the payload structure you received in the app while foreground. Normally it's different compared to Android. The iOS payload structure should be :

{
   "aps" : {
     "alert" : {
       "body" : "great match!",
       "title" : "Portugal vs. Denmark",
     },
     "badge" : 1,
   },
   "Custom_Data" : "Game level name"
 }

这篇关于iOS应用未收到来自Firebase的后台推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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