title: Remote Control event in iOS with Swift
body: <p>Trying to figure out how to read the Apple headphone's volume buttons to use as a trigger for the camera shutter (as the Apple Camera app does). </p>
  
  <p>From the documentation on <a href="https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html" rel="noreferrer">Remote Control Events</a>, <a href="https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIResponder_Class/index.html#//apple_ref/occ/instm/UIResponder/remoteControlReceivedWithEvent:" rel="noreferrer">
  Remote Control Received With Event</a>, and <a href="https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch14p643ducking/ch27p912ducking/Player.swift" rel="noreferrer">this git repo</a>, I've pieced together that I'll probably need an <code>AVAudioPlayer</code> object, <code>.beginReceivingRemoteControlEvents()</code>, and <code>remoteControlReceivedWithEvent</code>, along with making this view <code>canBecomeFirstResponder()</code> <code>return true</code>.</p>
  
  <pre><code>import UIKit
  import AVFoundation
  
  class ViewController: UIViewController, AVAudioPlayerDelegate {
      var player: AVAudioPlayer!
      override func viewDidLoad() {
          super.viewDidLoad()
  
          var session: AVAudioSession = AVAudioSession.sharedInstance()
          session.setActive(true, error: nil)
      }
  
      override func viewDidAppear(animated: Bool) {
          super.viewDidAppear(animated)
          println("viewDidAppear worked...")
          self.becomeFirstResponder()
          UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
      }
  
      override func canBecomeFirstResponder() -&gt; Bool {
          return true
      }
  
      override func remoteControlReceivedWithEvent(event: UIEvent) {
          let rc = event.subtype
          println("does this work? \(rc.rawValue)")
          //takePicture()
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
      }
  }
  </code></pre>
  
  <p>I expected to get <code>"does this work"</code> when hitting the volume buttons on the headphones, instead I just see it adjust the headphone volume like normal. So I must be missing something, maybe with a <code>delegate</code> or <code>AVSession</code>? </p>