iOs 7.0 doesn't play a sound when an alert is received. Sound is enabled in the notification center for the specific app. In the docs it writes: "The sound must be located in your project's resources and must be a caf file".
I created a 'beep.caf' file but since I am using phonegap build, there is no resources folder in my project. I tried putting it in the root folder (www) but doesn't work.
So where should i put the caf file so as it can be located by the plugin?
Putting the file into the www folder does not work. If you are using PGB you cannot make use of the sound
property.
But instead you can make use of the cordova Media Plugin or use the html5 audio api.
You mean putting extra code in foreground/background functions so as to play a sound? How can I make use of cordova media plugin to play a sound when a notification is received in status bar while the app is closed (the functions haven't even executed yet). Is that possible? or have i misunderstood what you said?
OK, that would only work while the app is running.
The sound file has to be added to the project as a resource of the application bundle. Then you should be able to add the sound with sound: "www/beep.caf"
.
I have put the beep.caf file in www folder (which is the root folder for PGB) and tried sound: "www/beep.caf"
, sound: "/www/beep.caf"
and sound: "../www/beep.caf"
but nothing worked for me.
Have you got any other suggestions?
If it helps the location.href for the file is: file:///var/mobile/Applications/{ID}/Agenda.app/www/beep.caf
So, any ideas about this?
For sure it would work if you could put the file inside the root folder of the iOS project. But thats not possible since you are using PGB.
Because I have no real device I cannot test it, because with the simulator its not possible to access the notification center settings.
Could you, at some point, change the plugin in order to be able in finding the sound (on iOS) when the sound file is located in the www folder, so as PGB users can use it as well?
thx in advance!
Maybe that (6abf363a878fd0fddc2dc612fd4c2fd0bb138e7b) helps. But I cannot test it.
to @Ionas83
if you want to play a sound锛宮aybe you can use the phonegap code to instead
var my_media = new Media("http://remotedomain/beep.wav");
my_media.play();
That would work while the app is running.
to @katzer
I really to a test as same as @Ionas83
the sound in ios7 really doesn't work
Sound is enabled in the notification center for the specific app
in Android you can use the remote sound
sound: http://remote/beep.wav
but in ios7锛宨t can't
but we can use this code to instead
var my_media = new Media("http://remotedomain/beep.wav");
my_media.play();
It would be great if someone with a real device could analyse the issue with iOS. With the emulator its not possible because I cannot enable the sound in the notification center.
Hi,
I added the sound files in a 'sound' folder to xcode and try to play them by using:
sound: 'sound/done.caf',
it only plays the ios default notification sound when the notification comes.
I also commented on it in issue #90 but I just tested it on both the simulator and the device:
Given that my files are in the folder www/sounds/soundname.caf
,
_APPLocalNotification.m / line 235_:
this works:
notification.soundName = [NSString stringWithFormat:@"www/sounds/%@", sound];
this does not work:
notification.soundName = [self.commandDelegate pathForResource:[NSString stringWithFormat:@"sounds/%@", sound]];
This is confirmed to be the case on an iPhone 5S with the latest iOS 7, and the iPhone Simulator, also on iOS 7. Maybe you can check this out some time?
@mgerlach-klick Your simulator plays sound?
Yup, it does
Is there a secret setting I have to change? Because my one don't like to play any sound. Even not the default notification sound. With iOS 6 I had not that issue.
Hrm, I doubt it. Mavericks, XCode 5, iPhone Simulator with 7.0.3. Try changing the line I mentioned above, that made my simulator and my phone both play a notification sound (neither one did before the fix)
sorry for late reply, Thanks @mgerlach-klick your trick works on the real device.
@katzer, the current version only plays default iOS notification sound when fired, is there any reason why you changed the way to bind sound file to be adding it in xcode?
I have reverted the change. Does it work now with sound: "www/sounds/soundname.caf"
?
@katzer Can you please explain what you mean by this "The sound file has to be added to the project as a resource of the application bundle. " I am running into this problem and I have the code fix mentioned above by @mgerlach-klick . It is clear that iOS is not able to see my notification file. I am on iOS7 ipod touch.
Can anyone help me with this?
And yes sorry I opened a separate issue because I did not discover this post till much later.
Thank you
@mitos14, simply add your sound file to your project through Xcode. For example inside your projects root folder. And specify the sound URI relative to the root project (sound: 'www/beep.caf').
Please note that iOS plays the sound only if the app runs in background.
I had the same issue.
Then I put sound file into www/sounds/done.caf
and referred it in js as:
var snd = new Media("sounds/done.caf")
snd.play();
Then file was playing fine both in simulator and real device (5s ios 7.0)
@nopium,
if your sound file is located under _www/sounds/done.caf_, use the following and your sound will play even the app isn't running*:
cordova.plugins.notification.local.schedule({
text: "...",
sound: "file://sounds/done.caf"
});
*Requires version 0.8
I had the same problems with ios sounds.... nothing whatsoever!
Than I found this post:
http://leifwells.com/post/2016-06-03-local-notifications/
--> sound: 'res://platform_default'
everything WORKED!
1 year too late, I know, but I had the same issue and that fix didn't work for me, but this did:
installed:
cordova-plugin-media
cordova-plugin-file
put my wav file in www/audio
then used:
var wavURL
if(device.platform == 'iOS') {
console.log("Using ios file system.")
wavURL = 'cdvfile://localhost/bundle/www/audio/chimes.wav'
} else {
console.log("Using android file system.")
wavURL = 'file:///android_asset/www/sound/chimes.wav'
}
$cordovaMedia.newMedia(wavURL).play();
Most helpful comment
I had the same problems with ios sounds.... nothing whatsoever!
Than I found this post:
http://leifwells.com/post/2016-06-03-local-notifications/
--> sound: 'res://platform_default'
everything WORKED!