You can determine if the volume button is pressed in the application, but uses the Apple private API. Since they do not allow the use of their private APIs in your application, this immediately leads to the failure of your application, so use this at your own risk.
In your viewDidLoad: for example:
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(18, 340, 284, 23)]; [self.view addSubview:volumeView]; [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(volumeDidChange:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
source share