简体   繁体   English

FCM flutter 启用通知振动

[英]FCM flutter enable notification vibration

I'm developing a Flutter application for Android and IOS. I have created notification channels for Android according to this article .我正在为 Android 和 IOS 开发一个 Flutter 应用程序。我已经根据这篇文章为 Android 创建了通知渠道。

My node.js payload:我的 node.js 负载:

const payload = {
      notification: {
        title: "title",
      },
      android: {
        priority: "high",
        ttl: 60 * 60 * 1,
        notification: {
          channel_id: 'YO',
        },
      },
      apns: {
        payload: {
          aps: {
            sound: "sound_03.caf"
          }
        },
        headers: {
          "apns-collapse-id": "yo",
          "apns-priority": "10"
        }
      },
      priority: 10
    }

My notifications are working just fine, for both Android and IOS using.对于 Android 和 IOS 使用,我的通知工作正常。 The problem is that vibration is disabled by default.问题是默认情况下禁用振动。

How to enable notification vibration for Android and IOS for Firebase Cloud Messaging?如何为Firebase云消息启用Android和IOS的通知振动?

You can set the sound property to default so it makes uses the default sound if sound is enabled and it vibrates if the device is on vibrate.您可以将sound属性设置为default ,以便在启用声音时使用默认声音,如果设备处于振动状态则它会振动。

You can update your payload to this:您可以将有效负载更新为此:

const payload = {
  notification: {
    title: "title",
    sound: "default"
  },
  android: {
    priority: "high",
    ttl: 60 * 60 * 1,
    notification: {
      channel_id: 'YO',
    },
  },
  apns: {
    payload: {
      aps: {
        sound: "default"
      }
    },
    headers: {
      "apns-collapse-id": "yo",
      "apns-priority": "10"
    }
  },
  priority: 10
}

For me, I only needed to add it to the notification portion of the message payload.对我来说,我只需要将它添加到消息负载的notification部分。

Below is how it looks in Typescript (but the message JSON is all that matters).下面是它在 Typescript 中的样子(但消息 JSON 才是最重要的)。

let tokens = ...
let message = {
    message: {
        notification: {
            title: title,
            body: body,
            sound: 'default', // <----- All I needed
        },
        data: {
            ...
        },
    }
}

firebase.messaging().sendToDevice(tokens, message)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM