Tim Johnsen Tim Johnsen - 1 year ago 152
iOS Question

Hide volume HUD in iOS 8

In versions prior to iOS 8, there was a simple trick to hiding the system volume overlay. You'd simply create an

and embed it in your view hierarchy somewhere. This is documented here http://stackoverflow.com/a/7888977/3943258 and in many other Stack Overflow responses.

However, I'm finding this trick doesn't seem to work in iOS 8. I'm pulling my hair out trying to figure out how to fix it. Does anybody know if there's a way to do this in iOS 8?

One thing of note is that the app I'm doing this in has an active
while I'm trying to hide the HUD (volume buttons act as the shutter on a camera). Not sure if there might be some side effects of that.

Answer Source

Alright, this abuses a private API but I've found that it works.

- (void)setVolumeHidden:(BOOL)hidden
    NSString *str1 = @"etSystemV";
    NSString *str2 = @"eHUDEnabled";
    NSString *selectorString = [NSString stringWithFormat:@"s%@olum%@:forAudioCategory:", str1, str2];
    SEL selector = NSSelectorFromString(selectorString);

    if ([[UIApplication sharedApplication] respondsToSelector:selector]) {
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIApplication instanceMethodSignatureForSelector:selector]];
        invocation.selector = selector;
        invocation.target = [UIApplication sharedApplication];
        BOOL value = !hidden;
        [invocation setArgument:&value atIndex:2];
        __unsafe_unretained NSString *category = @"Ringtone";
        [invocation setArgument:&category atIndex:3];
        [invocation invoke];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download