在生产构建离子3中没有获得本地通知声音 [英] Not getting local Notification Sound in production build ionic 3
本文介绍了在生产构建离子3中没有获得本地通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 ionic 3 本地通知声音有疑问.当我进行调试构建时,声音就来了.
I have an issue with ionic 3 local notification sound. The sound is coming when I did debug build.
它没有进入生产版本,我也尝试将声音值设置为res://platform_default"(没有得到声音).请帮我.提前致谢.
It's not coming in production build and also I tried by setting the sound value as "res://platform_default"(not getting the sound). Please help me. Thanks in advance.
在我的代码下面.
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();*/
});
推荐答案
尝试使用 三元 运算符分配 mp3 声音,而不调用函数分配它
Try assigning the mp3 sound by using ternary operator without calling the function to assign it
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: this.platform.is('android') ? 'file://assets/sounds/Rooster.mp3' : 'file://assets/sounds/Rooster.caf',
});
参考离子文档 https://ionicframework.com/docs/native/local-notifications/
这篇关于在生产构建离子3中没有获得本地通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文