iOS Device Volume

By using the private framework, Celestial, we can simply get and set the volume or monitor its change. The class used is AVSystemController in Celestial framework.

We can get or set the audio of either the active audio category or a specific audio category.

1) Active audio category:

float volume;
[[AVSystemController sharedAVSystemController] getActiveCategoryVolume:&volume andName:nil];
[[AVSystemController sharedAVSystemController] setActiveCategoryVolumeTo:1.0];

(Optional) Also get the name of the active audio category:

float volume;
NSString *categoryName;
[[AVSystemController sharedAVSystemController] getActiveCategoryVolume:&volume andName:&categoryName];

2) Specific audio category:

float volume;
[[AVSystemController sharedAVSystemController] getVolume:&volume forCategory:@"CATEGORY_HERE"];
[[AVSystemController sharedAVSystemController] setVolumeTo:1.0 forCategory:@"CATEGORY_HERE"];

Furthermore, we can also monitor the change of device volume with the following code.

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

- (void)volumeChanged:(NSNotification *)notification {
	float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
}

Reference: List of available audio categories

Hide volume HUD view

Notice: This method is undocumented and only for tweaks or apps that will not be submitted to AppStore.

How to use:

[[UIApplication sharedApplication] setSystemVolumeHUDEnabled:NO forAudioCategory:@"CATEGORY_HERE"]; // for a specific audio category

OR

[[UIApplication sharedApplication] setSystemVolumeHUDEnabled:NO];

Relevant header (private methods):

@interface UIApplication (Private)

- (void)setSystemVolumeHUDEnabled:(BOOL)enabled forAudioCategory:(NSString *)category;
- (void)setSystemVolumeHUDEnabled:(BOOL)enabled;

@end

Reference: List of available audio categories