美文网首页
iOS隐藏系统声音弹框并拦截音量变化

iOS隐藏系统声音弹框并拦截音量变化

作者: small_Sun | 来源:发表于2018-12-26 16:06 被阅读21次

    //隐藏系统声音弹框

    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("蓝牙拦截")
    }
    }

    相关文章

      网友评论

          本文标题:iOS隐藏系统声音弹框并拦截音量变化

          本文链接:https://www.haomeiwen.com/subject/fughlqtx.html