Hussaan S
Hussaan S

Reputation: 281

Restore ringer volume IOS using avsystemcontroller is not working

I set iphone ringer volume to zero by using following code (Its Working). My problem is i want to restore and with the same code just changing volume level is not working. Please suggest an appropriate way to do this.

NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/Celestial.framework"];
BOOL success = [bundle load];
Class avSystemControllerClass = NSClassFromString(@"AVSystemController");
id avSystemControllerInstance = [avSystemControllerClass performSelector:@selector(sharedAVSystemController)];
NSString *soundCategory = @"Ringtone";


NSInteger *newVolumeLevel = 0;


NSInvocation *volumeInvocation = [NSInvocation invocationWithMethodSignature:
                                  [avSystemControllerClass instanceMethodSignatureForSelector:
                                   @selector(setVolumeTo:forCategory:)]];

[volumeInvocation setTarget:avSystemControllerInstance];
[volumeInvocation setSelector:@selector(setVolumeTo:forCategory:)];
[volumeInvocation setArgument:&newVolumeLevel atIndex:2];
[volumeInvocation setArgument:&soundCategory atIndex:3];
[volumeInvocation invoke];

i tried to set newvolumelevel to 5 8 10 but its not working.

P.S i know its an private framework and app will not be approved. :)

Upvotes: 0

Views: 501

Answers (1)

Viral Savaj
Viral Savaj

Reputation: 3389

The only problem you are facing is the NSInteger. Take a float to set volume, like

float newVolumeLevel=0.8;

and everything else is same, no changes.

HTH.

Happy Coding

Upvotes: 1

Related Questions