【发布时间】:2019-02-22 20:33:01
【问题描述】:
我对 ionic 3 本地通知声音有疑问。当我进行调试构建时,声音就来了。
它没有进入生产版本,我也尝试将声音值设置为“res://platform_default”(没有得到声音)。请帮我。提前致谢。
在我的代码下面。
import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, Platform, AlertController} from 'ionic-angular';
import {LocalNotifications} from '@ionic-native/local-notifications';
@IonicPage()
@Component({
selector: 'page-notifications',
templateUrl: 'notifications.html',
})
export class NotificationsPage {
data = {title: '', description: '', date: '', time: ''};
constructor(public navCtrl: NavController,
public localNotifications: LocalNotifications,
public platform: Platform,
public alertCtrl: AlertController) {
}
submit() {
console.log(this.data);
var date = new Date(this.data.date + " " + this.data.time);
console.log(date);
this.localNotifications.requestPermission().then((permission) => {
this.localNotifications.schedule({
id: 0,
text: 'Delayed ILocalNotification',
trigger: {at: date},
foreground:true,
vibrate: true,
led: {color: '#FF00FF', on: 500, off: 500},
data: {mydata: 'My hidden message this is'},
// sound: 'res://platform_default',
sound: this.setSound(),
});
let alert = this.alertCtrl.create({
title: 'Congratulation!',
subTitle: 'Notification setup successfully at ' + date,
buttons: ['OK']
});
alert.present();
this.data = {title: '', description: '', date: '', time: ''};
});
}
setSound() {
if (this.platform.is('android')) {
return 'file://assets/sounds/Rooster.mp3'
} else {
return 'file://assets/sounds/Rooster.caf'
}
}
}
在仪表板页面中
this.localNotifications.on('click').subscribe(
(datas: any) => {
alert('in_is');
alert(JSON.stringify(datas));
/*let alert = alertCtrl.create({
title: notification.title,
subTitle: json.mydata
});
alert.present();*/
});
【问题讨论】:
标签: ionic-framework ionic2 ionic3