ionic cordova本地通知听起来不起作用



我正在尝试使用本地通知构建我的ionic移动应用程序,我想在通知中包含声音。我已经尝试将声音文件添加到资源文件夹,并添加以下代码。但仍然不起作用。

recurringMonthAlarm(alarmdata,eleindex){
this.localNotifications.schedule({
id: eleindex,
title: alarmdata.title,
text: alarmdata.desc,
sound: this.setSound(),
foreground: true,
trigger: {firstAt: alarmdata.startTime,
every: ELocalNotificationTriggerUnit.MONTH
}

});
}

setSound() {
return 'file://audio/alarmsound.wav';
}

看起来像是您的文件路径问题,将您的声音文件添加到您的资产文件夹中。

尝试:

setSound() {
if (this.platform.is('android')) {
return 'file://assets/sounds/shame.mp3' // for Android
} else {
return 'file://assets/sounds/bell.mp3' // for iOS
}
}

最新更新