I'm trying to trigger different actions inside only my own app using buttons of plugged headset (something similar what pressy does). I noticed however that no matter if I use MPRemoteCommandCenter
or remoteControlReceivedWithEvent
delegate, I receive events with a noticable lag. What makes matter worse is that if I try double press button fast I will only get one UIEventTypeRemoteControl
.
Does anyone experience similar issue, know the reason of this or even better know some workaround? Tested under ios8 and ios9.
A quick double-press is indeed a single user action, as this is the desired behaviour in almost any application which uses the headset control for input. It saves developers having to debounce, queue and parse incoming control events manually and is a Good Thing(tm)!
For this to work the system will introduce a small amount of lag while it waits for further user input. It should only take a few hundred milliseconds for this to complete, after which you'll receive the event in your code.
A long, painful, but hopefully useful example of double-press detection:
See how the delay is necessary for single/double/triple-press detection.
When the event reaches your application it will have a subtype which describes what type of click the user made:
let rc = event!.subtype
print("received remote control \(rc.rawValue)") // 101 = pause, 100 = play
switch rc {
case .RemoteControlTogglePlayPause:
// ..
case .RemoteControlPlay:
// ..
case .RemoteControlPause:
// ..
default:break
}
An answer on a similar question pointed out these event code integers will be something like;
100 = play
101 = pause
103 = single mic click
104 = double mic click
105 = triple mic click
etc ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With