3

I am using cordova-plugin-local-notifications plugin. Now I have issue to get my sound file in both Android and iOS.

window.plugin.notification.local.add({
    id:         '0001',   
    date:       new Date,      
    message:    'hello',
    title:      'title',  
    badge:      1,
    sound:      'www/resources/audio/beep.mp3', 
    autoCancel: true, 
    ongoing:    true 
});

What I need to do I need to change in native side my app in sencha touch.

Cœur
  • 37,241
  • 25
  • 195
  • 267
RaviPatidar
  • 1,438
  • 1
  • 18
  • 29

1 Answers1

7

I think the plugin is updated and the "window.plugin.notification.local.add" method is deprecated now, now it is "window.plugin.notification.local.schedule", the "date" is now "at" and "message" is now "text".

To install plugin use below command:

cordova plugin add de.appplant.cordova.plugin.local-notification && cordova prepare

I have a plugin version installed: 0.8.1, before it is 0.7.4 at my end.

Set "sound" as like below:

sound: "file://resources/audio/beep.mp3"

so your new method will be like below:

window.plugin.notification.local.schedule({
    id:         '0001',
    at:         new Date,
    text:       'hello',
    title:      'title',
    badge:      1,
    sound:      'file://resources/audio/beep.mp3',
    autoCancel: true,
    ongoing:    true
});

It is working fine for me on iOS and Android devices. Hope it will be helpful to you :)

Saim Ehsan
  • 21
  • 6
Rohit Sharma
  • 136
  • 4
  • 1
    Thank - you very much sir . I have applied code given by you and change plugin as you suggested now it's working fine for me I hope it will help to others – RaviPatidar Jul 16 '15 at 06:51
  • HI Ravi, Im having the same issue, and my code is quite simple, any ideas why there would be popups and yet no sound? window.plugin.notification.local.schedule({ id: 1, title: "Title", text: "Your location has changed", sound: "file://sound/notification.caf" }); – SM3RKY Oct 14 '15 at 01:54
  • @Rohit, what version of `cordova`, `cordova-ios`, `cordova-android` and `iOS` are you using? I can get sound working on Android and iOS emulator but not on iPhone running iOS 9.3.1 – santeko Apr 13 '16 at 00:43