Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS 14上从未触发SystemVolumeDidChangeNotification_Ios_Swift_Nsnotificationcenter_Ios14 - Fatal编程技术网

在iOS 14上从未触发SystemVolumeDidChangeNotification

在iOS 14上从未触发SystemVolumeDidChangeNotification,ios,swift,nsnotificationcenter,ios14,Ios,Swift,Nsnotificationcenter,Ios14,目标是监视卷更改事件及其值。跟着导游走 在iOS 14上。*当我尝试观察卷更改事件时,该事件似乎在卷更改后从未被触发 import MediaPlayer override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) NotificationCenter.default.addObserver(self, selector: #selector(volumeChange(_:)), n

目标是监视卷更改事件及其值。跟着导游走

在iOS 14上。*当我尝试观察卷更改事件时,该事件似乎在卷更改后从未被触发

import MediaPlayer

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    NotificationCenter.default.addObserver(self, selector: #selector(volumeChange(_:)), name: Notification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil)
}

@objc func volumeChange(_ notification: NSNotification) {
    let userInfo = notification.userInfo!
    let volume = userInfo["AVSystemController_AudioVolumeNotificationParameter"] as! Double

    print("volume:\(volume)")
}

beginReceivingRemoteControlEvents
需要首先调用

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    UIApplication.shared.beginReceivingRemoteControlEvents() // <- THIS LINE

    NotificationCenter.default.addObserver(self, selector: #selector(volumeChange(_:)), name: Notification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil)
}
覆盖函数视图显示(uu动画:Bool){
super.viewdide显示(动画)

UIApplication.shared.beginReceivingRemoteControlEvents()//谢谢,我想知道为什么在iOS 14.1之前我们从来不需要使用它。