//隐藏系统声音弹框
1、声明两个变量
let volumeView = MPVolumeView() //} 为了隐藏声音弹框
var volumeViewSlider = UISlider() //} 为了隐藏声音弹框
2、循环遍历
for view in volumeView.subviews{
if view.classForCoder.description()== "MPVolumeSlider"{
volumeViewSlider = UISlider()
break
}
}
volumeView.frame = CGRect(x: -100,y: -100,width: 40,height: 40)
self.view.addSubview(volumeView)
//拦截系统声音调整
//添加监听
NotificationCenter.default.addObserver(self,selector: #selector(self.changeVolumSlider),name: [NSNotification.Name](http://nsnotification.name/)(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"),object: nil)
UIApplication.shared.beginReceivingRemoteControlEvents()
@objc func changeVolumSlider(notification:NSNotification){ //记得参数加上,才能得到信息
if let volum:Float = notification.userInfo?["AVSystemController_AudioVolumeNotificationParameter"]as! Float?{
print("蓝牙拦截")
}
}
网友评论