ios 获取是否静音模式_如何检测iOS设备是否处于静音模式?

I've been looking for hours and I can't seem to find any API that explains how to detect whether an iPhone ringer is in silent mode or not. This is what I'm talking about:

Is there anyway I can find out whether an iOS device's silent mode is on or off using Swift code? I'm specifically looking for iOS8 and up since the iOS5 ones have been deprecated. Thanks.

解决方案

I don't think there is and you probably don't need to directly call an API to detect if the device is muted or not. What you need to know is this:

When playing a sound, you will do something like:

try AVAudioSession.sharedInstance().setCategory({AVAudioSessionCategory})

try AVAudioSession.sharedInstance().setActive(true)

audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)

audioPlayer.prepareToPlay()

audioPlayer.play()

In the {AVAudioSessionCategory}, you can specify:

AVAudioSessionCategorySoloAmbient: Your audio is silenced by screen

locking and by the Silent switch

AVAudioSessionCategoryPlayBack: Your Audio continues with the Silent

switch set to silent or when the screen locks

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值