我一直在尝试制作一款具有闹钟功能的应用。我决定使用localnotification,因为它会播放声音甚至显示通知。
但它似乎没有用。
我已经尝试过Stack上提供的所有解决方案。但它既不播放自定义声音也不播放默认声音,也不显示任何LED颜色,仅显示通知。
这是我的代码:
ionViewDidLoad() {
// Schedule a single notification
this.callnotify();
}
callnotify()
{
this.localNotifications.schedule({
id: 1,
text: 'Single ILocalNotification',
sound: 'res://platform_default',
led: 'FF0000'
});
this.localNotifications.schedule({
text: 'Delayed ILocalNotification',
trigger: {at: new Date(new Date().getTime() + 7200)},
led: 'FF0000',
sound: 'file://assets/sounds/serious-strike.mp3'
});
}
答案 0 :(得分:1)
首先尝试一次设置一个通知。
constructor(public platform: Platform){}
ionViewDidLoad() {
this.callnotify();
}
callnotify(){
this.localNotifications.schedule({
text: 'Delayed ILocalNotification',
trigger: {at: new Date(new Date().getTime() + 7200)},
led: 'FF0000',
vibrate: true,
sound: this.platform.is('android') ? 'file://assets/sounds/serious-strike.mp3': 'file://assets/sounds/serious-strike.mp3',
});
}