Phonegap notification.beep ignore silent mode

627 views Asked by At

Hello I'm using cordova 2.7.0 and I need to use the notification.beep() method. But I've a problem, my app rings even if the phone is in silent mode.

any suggestions?

I'm using iphone 5.

1

There are 1 answers

0
user3116615 On

Update your code in CDVSound.m file

Note: (void)setVolume is for phonegap 3.4 , Im not sure if the function is same for other older versions as well.. But similar function must be there to set volume.

Add following 2 lines of code to function setVolume, This will set volume of the sound same as sound set on device.

float mVolume=[self getVolumeLevel];
volume = [NSNumber numberWithFloat: mVolume];

Complete code will be as follows

- (void)setVolume:(CDVInvokedUrlCommand*)command
{

    NSString* callbackId = command.callbackId;

    NSString* mediaId = [command.arguments objectAtIndex:0];
    NSNumber* volume = [command.arguments objectAtIndex:1 withDefault:[NSNumber numberWithFloat:1.0]];


    //This will set volume of the sound same as sound set on device.
    float mVolume=[self getVolumeLevel];
    volume = [NSNumber numberWithFloat: mVolume];



    if ([self soundCache] != nil) {
        CDVAudioFile* audioFile = [[self soundCache] objectForKey:mediaId];
        if (audioFile != nil) {
            audioFile.volume = volume;
        if (audioFile.player) {
            audioFile.player.volume = [volume floatValue];
        }
        [[self soundCache] setObject:audioFile forKey:mediaId];
    }
}

}