首页 > 解决方案 > 如果我有令牌数组,通过 FCM 发送通知的最佳方式

问题描述

我能够成功地将通知发送到单个令牌。

 var  body = {
                to: sendTo,
                data: {
                 custom_notification: {
                    title: "New notification",
                    body: 'msg',
                    sound: "default",
                    priority: "high",
                    show_in_foreground: true,
                    targetScreen: "detail"
                 }
               },
            priority: 10
      }

    axios({
        method: 'post', //you can set what request you want to be
        url: 'https://fcm.googleapis.com/fcm/send',
        data: body,
        headers: {
            "Content-Type": "application/json",                                                              
             "Authorization": "key=" + serverKey
                }
        }).then((res)=>{
              console.log(res)
        }).catch((e)=>{
            console.log(e)
        })

sendTo 现在是令牌数组

var sendTo = [T1,T2,T3....]

我必须遍历数组还是有其他方法?还有一件事我的通知既没有出现在锁定屏幕上,也没有在手机解锁时弹出。图像出现在顶部,我必须滚动通知托盘/菜单。如何解决这个问题?

标签: javascriptfirebasefirebase-cloud-messaging

解决方案


推荐阅读