Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

IOS custom push sound when app is in background #175

Closed
ghost opened this issue Sep 28, 2015 · 6 comments
Closed

IOS custom push sound when app is in background #175

ghost opened this issue Sep 28, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Sep 28, 2015

Is having a custom push sound when app is in the background still a problem with this new plugin? The old plugin was never able to do it. The only way I have been able to do it is with a pure objective c program.

@macdonst
Copy link
Member

@tmakaro Yes, you can play a sound on iOS. Check out issue #17 for more information.

@ghost
Copy link
Author

ghost commented Sep 29, 2015

I can't get it to work. alarm.caf works when app is in the forground only. When the app is in the background, all I get is the standard beep.
Where is my alarm.caf file supposed to be located? Am I running the wrong version?

@ghost
Copy link
Author

ghost commented Sep 30, 2015

It has something to do with what IOS thinks my root folder is and what cordova thinks my root folder is.

The following works when I store alarm.caf in the www folder: (works when app is in forground but not when app is in background)

{
    "aps": {
        "alert": "test alarm", 
        "sound": "alarm.caf"
    }
}

 push.on('notification', function (data) {
     if (data.sound) {
         var snd = new Media(data.sound);
         snd.play();
     }
 });

This change below makes it work when the app is in the background but not when it is in the forground:

{
    "aps": {
        "alert": "test alarm", 
        "sound": "www/alarm.caf"
    }
}

@macdonst
Copy link
Member

macdonst commented Oct 1, 2015

@tmakaro Yeah, iOS assumes that the sound file is in root folder of your app. Using:

{
    "aps": {
        "alert": "test alarm", 
        "sound": "www/alarm.caf"
    }
}

push.on('notification', function (data) {
     if (data.sound) {
         var snd = new Media(data.sound.substring(4));
         snd.play();
     }
 });

Should work in both background and foreground.

@ghost
Copy link
Author

ghost commented Oct 1, 2015

@macdonst Yes it does. Thank you!

@ghost ghost closed this as completed Oct 1, 2015
@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant