[iOS] Not able to override `.click` method
Documented behaviour
| Feature | Android | iOS | macOS | Web | | headset clicks | ✅ | ✅ | ✅ | ✅ |
Actual behaviour
The .click method does not get called on iOS.
On android when using headset buttons there will be 'I/flutter (24649): ----- LOG: click(MediaButton.media)` but on iOS no logs will be outputted.
Or if in iOS trying to override the .click method either in AudioPlayerHandler or MainSwitchHandler, it won't have any effect.
@override
Future<void> click([MediaButton button = MediaButton.media]) {
debugPrint('Do something...');
return super.click(button);
}
Minimal reproduction project
Official example: example_multiple_handlers.dart
Reproduction steps
- Run example_multiple_handlers.dart on an iOS device
- Connect your headset
- Start audio playback
- Use play/pause button on headset
Output of flutter doctor
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.78.0)
[✓] Connected device (4 available)
[✓] HTTP Host Availability
• No issues found!```
### Devices exhibiting the bug
iOS device with Jabra headset.
duplicated #1009
@ryanheise
Do you have any idea what could be the cause of this issue or guild me how I could debug it?
@ryanheise I'm not sure this is the right way to do, but I could get click event by:
Creating a new clickNext method
- (MPRemoteCommandHandlerStatus) clickNext: (MPRemoteCommandEvent *) event {
//NSLog(@"togglePlayPause");
[handlerChannel invokeMethod:@"click" arguments:@{
@"button":@(1)
}];
return MPRemoteCommandHandlerStatusSuccess;
}
and call it from
case ASkipToNext:
if (enable) {
[commandCenter.nextTrackCommand addTarget:self action:@selector(clickNext:)];
} else {
[commandCenter.nextTrackCommand removeTarget:nil];
}
break;
Do you have any recommendation?