title: Use earpods in swift
body: <p>I'm trying to get when you press the play / pause button of my earpods make an action. For this I am first trying to achieve change a text label ...</p>
  
  <p>According to look at various websites, they performed this same but it does not work. Is there anything missing me add?</p>
  
  <p>I have the following code in viewController.swift</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      canBecomeFirstResponder()
      UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  @IBOutlet weak var Cosa: UILabel!
  
  func play()  {
      Cosa.text = "Play"
  }
  
  override func canBecomeFirstResponder() -&gt; Bool {
      return true
  }
  
  override func remoteControlReceivedWithEvent(event: UIEvent?) {
      guard let event = event else {
          print("no event\n")
          return
      }
      guard event.type == UIEventType.RemoteControl else {
          print("received other event type\n")
          return
      }
      switch event.subtype {
      case UIEventSubtype.RemoteControlPlay:
          print("received remote play\n")
          play()
      case UIEventSubtype.RemoteControlPause:
          print("received remote pause\n")
      case UIEventSubtype.RemoteControlTogglePlayPause:
          print("received toggle\n")
      default:
          print("received \(event.subtype) which we did not process\n")
      }
  }
  </code></pre>