你好,我正在使用cordova 2.7.0,我需要使用notification.beep()方法。但是我有一个问题,即使手机处于静音模式,我的应用程序也会响铃。
有什么建议吗?
我正在使用iPhone 5。
更新 CDVSound.m 文件中的代码
注意:(void)setVolume 适用于 phonegap 3.4,我不确定该功能是否也适用于其他旧版本。但是必须有类似的功能来设置音量。
将以下 2 行代码添加到函数 setVolume,这将设置与设备上设置的声音相同的声音音量。
float mVolume=[self getVolumeLevel];
volume = [NSNumber numberWithFloat: mVolume];
完整的代码将如下所示
- (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];
}
}
}