2

I'm trying to detect when the volume buttons are pressed in iOS 15 by following this answer: https://stackoverflow.com/a/68296203

How exactly can I receive this notification and where do I find MPVolumeControllerSystemDataSource? It seems like this might be obvious (judging by the upvotes for the answer) but I just can't figure it out. Using this right now which is not working anymore on iOS 15:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];

How do I need to change the code to receive the notification on iOS 15?

PS: I'm aware that the documented way would be to use the outputVolume property instead, but for a few reasons I'd like to detect the volume button presses in this "incorrect" way.

viedev
  • 869
  • 1
  • 6
  • 16
  • 1
    In one of the answers about the very StackOverflow question you posted it says that this notification is no longer being sent on iOS 15 and that the correct mechanism is the KVO on the `outputVolume` property. I'm surprised the very fact that this mechanism broke and left you with this conundrum hasn't dissuaded you from using undocumented, private mechanisms to complete a task. Still, if you insist on going down that path, there is also an answer on the very question you linked that suggest the notification name has changed to `SystemVolumeDidChange` – Scott Thompson Nov 01 '21 at 03:42
  • Thanks for taking the time to answer, feeling a bit stupid now. For some reason I did not get that the notification name is indeed just `SystemVolumeDidChange` and not "AVSystemController_SystemVolumeDidChange". – viedev Nov 01 '21 at 11:22

0 Answers0