Ionic:是否可以将传入的推送FCM推送通知从显示到我的设备的时间推迟到特定时间 [英] Ionic: Is it possible to delay incoming push FCM push notification from showing to my device until a specific time

查看:54
本文介绍了Ionic:是否可以将传入的推送FCM推送通知从显示到我的设备的时间推迟到特定时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在为我的项目使用Firebase.这样做是每次将新记录添加到Firestore中的特定集合中时,我的Firebase函数都会被触发,从而将推送通知发送到订阅特定主题的用户的设备中.

So i am using Firebase for my project. And what is does is that every time a new record is added into a specific collection in Firestore, my Firebase Function will be triggered thus sending the push notification into the devices of users who are subscribe to a specific topic.

这是我用于Firebase功能的代码:

Here is the code that i used for Firebase Function:

exports.sendNotifications = functions.firestore
 .document('notifications/{sessionId}').onCreate(async event => {
  const newValue = event.data();

 // Gets data from the new notification record in Firestore.
 const topicId = newValue.topicId;
 const themeId = newValue.themeId;
 const colorId = newValue.colorId;
 let lable = newValue.lable;
 let header = newValue.header;

 // Limit the number of characters for push notifications
 if(header.length >= 50){
  header = header.substring(0,47) + "...";
 } if(lable.length >= 100){
  lable = lable.substring(0,97) + "...";
 }

 // Set the message for the notification.
 const payload = {
  notification: {
   title: header,
   body: lable,
  }
 }
 let options = {
  priority: 'high'
 };

 // Sends the notification to the users subscribed to the said topic
 return admin.messaging().sendToTopic(topicId, payload, options)
});

由于该函数触发并向所有我的用户同时订阅主题发送推送通知.设备(接收端)是否有可能在特定时间到来之前不显示我的功能发送的通知?

Since the Function triggers and sends push notifications to all my users subscribe to a topic at the same time. Is it possible for the device (the receiving end) to not show the notification sent by my Function up until a specific time comes?

由于我的Ionic应用程序的用户需要选择他们一天中的什么时间将接收来自云的推送通知.

Cause users of my Ionic app needs to choose what time of the day they will be receiving push notification from the cloud.

我知道,在Firebase控制台中,您可以使用表单手动发送通知,并设置发送通知的时间和日期,但这对我不利,因为我的用户没有设置相同的设置通知显示的时间和日期.

I am aware that in the Firebase console, you can send notifications manually using a form and set the time and date in where the notification will be sent, but this does not work on my favor since my users did not set the same time and date for notifications to be showing.

推荐答案

Firebase Cloud Messaging中没有此时传递消息" API.请参见 FCM计划交付日期或推送通知时间

There is no "deliver the message at this time" API in Firebase Cloud Messaging. See FCM Schedule delivery date or time of push notification

有两种方法可以实现您的目标:

There are two ways to reach your goal:

  1. 仅当您希望传递邮件时才呼叫FCM.这将要求您创建以一定间隔运行的云功能,然后在调用时仅在该时间间隔内传递邮件.
  2. 将消息作为数据消息传递,由您的应用程序处理.然后将消息保留在客户端上,直到准备好向用户显示为止.有关更多信息,请参见有关创建通知的Android文档./li>
  1. Only call FCM when you want the message to be delivered. This will require that you create a Cloud Function that runs at an interval, and then when it is called only delivers the messages for that interval.
  2. Deliver the message as a data message, which your app handles. And then hold the message on the client, until it is ready to display to the user. See the Android documentation on creating a notification for more on that.

这篇关于Ionic:是否可以将传入的推送FCM推送通知从显示到我的设备的时间推迟到特定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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