2

I'm trying to test the local notifications on iOS using Cordova.

Everything it's working fine except the sound, I only get the default notification sound, not the custom sound I've added in the options.

This is only happening on iOS.

Code:

var now = new Date().getTime(),
    _10_seconds_from_now = new Date(now + 3*1000);

window.plugin.notification.local.add({
            id:      1,
            title:   'Reminder',
            message: 'Dont forget to buy some flowers.',
            repeat:  'weekly',
            date:    _10_seconds_from_now,
            sound:  'www/alarms/burglar.caf'
});
AAhad
  • 2,805
  • 1
  • 25
  • 42
Daniel
  • 789
  • 2
  • 9
  • 23

3 Answers3

3

Okay, after a few looks in the objective-c code I finally made it work!

The solution it's very simple, but not documented anywhere. You have to put the prefix file:// and all will work. sound: 'file://alarms/factory.wav'

Example:

window.plugin.notification.local.add({
            id:      2,
            title:   'Reminder',
            message: 'Dont forget to buy some flowers blah blah blah.',
            repeat:  'weekly',
            date:    _10_seconds_from_now,
            sound:  'file://alarms/factory.wav'
        });
Daniel
  • 789
  • 2
  • 9
  • 23
2

API says:

Notification sound on iOS

Note: Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.

This selected answer suggested:

From the Cordova Docs:

  • Cordova implements beep by playing an audio file via the media API.
  • The user must provide a file with the desired beep tone.
  • This file must be less than 30 seconds long, located in the www/ root, and must be named beep.wav
Community
  • 1
  • 1
AAhad
  • 2,805
  • 1
  • 25
  • 42
2

I also faced that problem you can use this code as i applied and it's working fine for me

cordova local notification sound not working in ios and andorid

open the link I think it will help to you

Community
  • 1
  • 1
RaviPatidar
  • 1,438
  • 1
  • 18
  • 29