title: how to detect the changes of volume in iOS？
body: <p>I‘ve read a lot solution provided by stackOverFlow and gitHub, and all of them doesn's work for me.I've tried the following tow way:</p>
  
  <ol>
  <li>using audioSession</li>
  </ol>
  
  <pre class="lang-swift prettyprint-override"><code>override func viewWillAppear(_ animated: Bool) {
          let audioSession = AVAudioSession.sharedInstance()
          do {
              try audioSession.setActive(true, options: [])
          } catch {
              print("error")
          }
          // this print shows, got the current volume.
          //but what I need is the notification of the change of volume
          print("view will appear ,this volume is \(audioSession.outputVolume)")
          audioSession.addObserver(self,
                                   forKeyPath: "outputVolume",
                                   options: [.new],
                                   context: nil)
      }
  
  override class func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
          super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
          if keyPath == "outputVolume"{
              let audioSession = AVAudioSession.sharedInstance()
              let volume = audioSession.outputVolume
              //this print doesn't shows up
              print("observed volume is \(volume)")
          }
      }
  </code></pre>
  
  <ol start="2">
  <li>using notification</li>
  </ol>
  
  <pre class="lang-swift prettyprint-override"><code>    override func viewWillAppear(_ animated: Bool) {
          NotificationCenter.default.addObserver(self, selector: #selector(observed(_:)), name: Notification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"), object: nil)
      }
  
      @objc func observed(_ notification: Notification){
          print("observed")
      }
  </code></pre>
  
  <p>by the way, I'm using simulator(iPhone11, iOS13.1),Xcode version is 11.1</p>