在 iOS5 中检测静音模式? [英] Detect Silent mode in iOS5?

查看:22
本文介绍了在 iOS5 中检测静音模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去曾用这种方法检测是否启用了静音开关:

I have used this method in the past to detect if the silent switch is enabled:

- (BOOL)silenced {
    #if TARGET_IPHONE_SIMULATOR
    // return NO in simulator. Code causes crashes for some reason.
    return NO;
    #endif

    CFStringRef state;
    UInt32 propertySize = sizeof(CFStringRef);
    AudioSessionInitialize(NULL, NULL, NULL, NULL);
    AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

    if(CFStringGetLength(state) > 0)
        return NO;
    else
        return YES;
}

这不再适用于我的 iPad 或 iPhone 上的 iOS5.这是一个已知的问题?我无法在堆栈溢出或 Apple 开发论坛上找到任何答案.

This is no longer working in iOS5 on my iPad or iPhone. Is this a known issue? I haven't been able to find any answers on stack overflow or Apple dev forums.

希望能帮到你...

推荐答案

自 iOS 5 起,我们将无法再检测静音开关状态...

We won't be able to detect the silent switch state anymore since iOS 5...

Apple 的答案就在已接受的答案中:使用 AVAudioPlayer 检测 iPhone 的铃声/静音/静音开关不起作用?

The answer from Apple is there on the accepted answer : Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

这篇关于在 iOS5 中检测静音模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆