我可以从Firebase云功能发送静默推送通知吗?

尤金

是否可以从Firebase Cloud Function发送静默的APNs(iOS)远程通知如果是这样,该怎么办?我想在应用程序不在前台时将数据发送到iOS应用程序实例,而用户不会看到通知。

我目前发送的通知可供用户查看:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotifications = functions.database.ref('/events/{pushId}').onWrite(event => {
  const id = event.params.pushId

  const payload = {
    notification: {
      title: 'An event has occurred!',
      body: 'Please respond to this event.',
      event_id: id
    }
  };

  return admin.messaging().sendToTopic("events", payload);
});

我希望能够id在没有视觉通知的情况下将其发送到应用程序。

尤金

我想出了如何修改代码以成功发送静默通知的方法。我的问题是,我一直试图把content_availablepayload,当它真正应该是options这是我的新代码:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotifications = functions.database.ref('/events/{pushId}').onWrite(event => {
  const id = event.params.pushId

  const payload = {
    data: {
      title: 'An event has occurred!',
      body: 'Please respond to this event.',
      event_id: id
    }
  };

  const options = {
    content_available: true
  }

  return admin.messaging().sendToTopic("events", payload, options);
});

实施application:didReceiveRemoteNotification:fetchCompletionHandler之后,我在iOS设备上成功收到了静默通知userNotificationCenter:willPresent:withCompletionHandler

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何发送静默的推送通知有效负载

从Laravel发送Firebase推送通知

我可以从Web控制台编辑未发送/预定的“解析推送通知”吗?

是否可以使用云使用解析推送通知发送其他数据?

从Firebase控制台发送静默推送通知

Android Firebase云功能通知

Firebase托管可以从云功能服务缓存的数据吗?

Firebase部署功能发送推送通知时出错

X分钟后使用Firebase功能发送推送通知

未经通知允许,我可以使用Firebase云消息传递吗?(JavaScript)

如何编写Firebase Cloud Messaging功能以发送推送通知

我可以在本地运行Firebase Storage云功能吗?

Firebase云功能可以使用内存缓存吗?

如何每天触发Firebase云功能以根据条件更新字段并将推送通知发送到Android客户端

在React Native中使用Firebase云功能进行EXPO推送通知

我可以将fcm通知发送给Firebase UserId而不是设备令牌吗?

Firebase云功能不会通过异步发送推送通知

我可以同时在本地模拟云功能和托管吗?

我可以在Android上使用Google Drive推送通知吗

我可以在AppDelegate.m之外注册推送通知吗?

我们可以在不使用 Firebase 的情况下向全球发送通知吗?

CPU 和带宽密集型是否直接使用 Firebase 云消息传递发送推送通知?

Android 中的 Firebase 云功能(Cron Jobs)可以吗?

在 IOS Firebase 云功能中未收到推送通知

是否允许通过静默推送通知发送位置数据?

我们可以使用 fcm-node 推送通知将对象发送到数据中吗

我可以使用 fcm 向其他用户发送推送通知吗?

使用 Firebase 云消息传递定期在 android 中发送推送通知

我可以在 firebase 云消息控制台中向特定用户发送通知吗