Reputation: 71
I'm using MPVolumeView to allow the user to control his preferred audio route when using my application.
The view is presented by this code:
self.volumeView = [[MPVolumeView alloc] initWithFrame:self.view.frame];
self.volumeView.showsVolumeSlider = NO;
[self.view addSubview:self.volumeView];
When the user taps the audio route button a menu appears with the available options.
The issue: The screen that shows the volume view, might need to be hidden because of various events my application handles and I would like to hide the audio route menu at the same time (if it's currently presented)
My question: Does anybody know if it's possible to manually dismiss MPVolumeView's audio route selection menu without the user having to press the cancel button?
Thanks!
Upvotes: 7
Views: 638
Reputation: 1468
on iOS 8, you can use below code which use 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)];
}
}
}
Upvotes: 0