katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.75k forks source link

Selected sound file does not play for my notification! Ionic 4 #1751

Open CreativeArtDesign opened 5 years ago

CreativeArtDesign commented 5 years ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

I got a notification with default notification sound that default in the phone settings sound, but the sound that i choose to play in my scheduled notification wont work. The only thing is i getting a notification but no sound file is played when i have set a own file.

Should i not get sound from the mp3 file i selected.

Have i missed anything?

Your Environment

General summary of the issue: When notification with sound is triggered while iphone is muted, it's not playing.

Expected Behavior

When getting a notification play a sound file i have selected.

sound: 'file://assets/tone_nokia.mp3',

Actual Behavior

I got a Notification but i can not get the mp3 file to start play.

Steps to Reproduce

import { Component } from '@angular/core';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { Storage } from '@ionic/storage';
import { NavController, AlertController, Platform } from '@ionic/angular';
import { ToastController } from '@ionic/angular';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})

export class HomePage {
  constructor(
    public navController: NavController,
    public navCtrl: NavController,
    private platform: Platform,
    private localNotifications: LocalNotifications,
    private alertController: AlertController,
    private toastController: ToastController) {

      this.localNotifications.on('trigger').subscribe(notification => {
          this.presentToast();
      });
      this.localNotifications.on('yes').subscribe(notification => {
          this.presentAlert(notification.data.meetingId);
      });
      this.localNotifications.on('no').subscribe(notification => {
          this.presentAlert(notification.data.meetingId);
      });
    }

// TRIGGER
  async presentToast() {
    const toast = await this.toastController.create({
      message: 'Athan spelas upp!',
      duration: 2000
    });
    toast.present();
  }

  async presentAlert(test) {
    const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      message: test,
      buttons: ['OK']
    });

    await alert.present();
  }

// On load or every check!
  scheduleNotification() {
    var myDate = new Date(2019, 1, 12, 9, 4, 5, 0);  // create a date object fo the 'trigger' 'at'
    var arrayOfNotifications = [{
        id: 1,
        foreground: true,
        trigger: { at: myDate }, // MUST be a date object
        text: 'Abdelbaset Athan spela upp.',
        title: 'Spela upp Athan',
        data: { meetingId:"Athan - 1" },
        sound: 'file://assets/sms.mp3',
      }];
      this.localNotifications.schedule(arrayOfNotifications);

  }

}
this.localNotifications.addActions('yes-no', [
    { id: 'yes', title: 'Yes' },
    { id: 'no',  title: 'No'  }
]);

I tried to put it in scheduleNotification() method but no buttons or sound are working.

And put the actions in scheduler:

actions: 'yes-no',

If i put this code as actions in my scheduler the foreground stop to work so i think there are an issue. i don't know.

// On load or every check!
  scheduleNotification() {
    this.localNotifications.addActions('yes-no', [
        { id: 'yes', title: 'Yes' },
        { id: 'no',  title: 'No'  }
    ]);

    var myDate = new Date(2019, 1, 12, 9, 31, 15, 0);  // create a date object fo the 'trigger' 'at'
    var arrayOfNotifications = [{
        id: 1,
        foreground: true,
        trigger: { at: myDate }, // MUST be a date object
        text: 'Abdelbaset Athan spela upp.',
        title: 'Spela upp Athan',
        data: { meetingId:"Athan - 1" },
        sound: 'file://assets/tone_nokia.mp3',
        actions: 'yes-no',
      }];
    this.localNotifications.schedule(arrayOfNotifications);

  }

Any ide? I tried to clear upp the code so you easy can see what i am doing.

Or should i install the beta version? if so how do I do that?

MInesGomes commented 4 years ago

I have the same problem. https://github.com/ionic-team/ionic/issues/19696 and it seems missing the "channel" as described here

https://distriqt.github.io/ANE-PushNotifications/m.FCM-GCM%20Payload

Sounds on individual notifications were deprecated in Android O (API 26). You now have to set them on a channel.

@CreativeArtDesign did you found a solution?