Disable native MPVolumeView iOS route menu

I use MPVolumeView to allow the user to control his preferred audio route when using my application.

The view is represented by this code:

self.volumeView = [[MPVolumeView alloc] initWithFrame:self.view.frame]; self.volumeView.showsVolumeSlider = NO; [self.view addSubview:self.volumeView]; 

When the user deletes the audio route button, a menu appears with the available options.

Problem: The screen displaying the volume view may need to be hidden due to various events being processed by my application, and I would like to hide the audio route menu at the same time (if it is currently presented)

My question is: Does anyone know if it is possible to manually disable the MPVolumeView route selection menu without pressing the cancel button?

Thanks!

+6
source share
1 answer

on iOS 8, you can use below code that uses a private API

  NSArray *windows = [[UIApplication sharedApplication] windows]; for (UIWindow *window in windows) { if ([NSStringFromClass([window class]) isEqualToString:@"_MPAVRoutingSheetSecureWindow"]) { UIView *view = [window.subviews firstObject]; if ([NSStringFromClass([view class]) isEqualToString:@"MPAVRoutingSheet"]) { [view performSelector:@selector(dismiss)]; } } } 
0
source

Source: https://habr.com/ru/post/978682/


All Articles