Skip to content

Instantly share code, notes, and snippets.

@Nexuist
Last active August 12, 2016 13:34
Show Gist options
  • Save Nexuist/d16eccace2a401111a731c3ce11b3321 to your computer and use it in GitHub Desktop.
Save Nexuist/d16eccace2a401111a731c3ce11b3321 to your computer and use it in GitHub Desktop.
A command line tool for iOS that can get and set different volume categories.
// Last modified Jan 22, 2014
#include <stdlib.h>
@interface AVSystemController : NSObject
+ (id)sharedAVSystemController;
- (BOOL)setActiveCategoryVolumeTo:(float)arg1;
- (BOOL)getActiveCategoryVolume:(float*)arg1 andName:(id*)arg2;
@end
int main(int argc, char* argv[]) {
AVSystemController *controller = [AVSystemController sharedAVSystemController];
if (argc > 1) {
float volume = atof(argv[1]); // atof returns 0 if it can't be converted into a float
[controller setActiveCategoryVolumeTo:volume];
printf("set current volume to %f\n", volume);
}
else {
// no arguments present
// display current category and volume
float volume;
NSString *name;
[controller getActiveCategoryVolume:&volume andName:&name];
printf("%s\n%f\n", [name UTF8String], volume);
}
return 0;
}

Usage

$ vol
Ringtone
0.49
$ vol 1.0
set volume to 1.0

Other Resources

This article has a nice explanation on the audio category system used by iOS.

Makefile Example

export ARCHS = armv7 arm64
include theos/makefiles/common.mk

TOOL_NAME = vol
vol_PRIVATE_FRAMEWORKS = Celestial
vol_FILES = main.mm

include $(THEOS_MAKE_PATH)/tool.mk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment