@elgibor-solution/fcm-custom-sound
FCM自定义通知声音
npm i --save @elgibor-solution/fcm-custom-sound

Nativescript FCM 自定义声音通知

firebase云消息(FCM)的自定义通知声音。 目前仅适用于Android

安装

ns plugin add @elgibor-solution/fcm-custom-sound

用法

# app.component.ts

import { customSound, CustomSoundOptions } from '@elgibor-solution/fcm-custom-sound';

const options: CustomSoundOptions = [
{ channelId: 'channel_1', audio: 'notif' },
{ channelId: 'channel_2', audio: 'notif2' }
];

customSound(options);

API

方法 返回类型 描述
customSound(options: CustomSoundOptions[]) void 根据提供的配置选项播放自定义声音。

CustomSoundOptions 接口

名称 类型 描述
channelId string 自定义声音的通道标识符。
audio string 自定义声音的音频文件路径或资源标识符。目前仅支持.wav音频文件。音频文件应放置在文件夹:App_Resources/Android/src/main/assets/raw

⚠️ 重要!

为了在后台播放通知声音,发送FCM的后端必须根据Android应用程序指定的设置设置通道名称或ID。

音频文件必须为.wav格式,并放置在App_Resources/Android/src/main/assets/raw文件夹中。在CustomSoundOptions接口中的audio属性应只包含文件名,不带扩展名。例如,如果音频文件名为notif.wav,则只需要notif

作者

许可

Apache许可证版本2.0