Не получено местное звуковое оповещение в производственной сборке ionic 3 - PullRequest
0 голосов
/ 22 февраля 2019

У меня проблема со звуком уведомлений ionic 3 local.Звук идет, когда я сделал отладочную сборку.

Это не входит в производственную сборку, и я также попытался установить значение звука как «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();*/
            });

1 Ответ

0 голосов
/ 22 февраля 2019

Попробуйте назначить звук mp3 с помощью оператора ternary , не вызывая функцию для его назначения

 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/

...