我使用以下代码(其工作)将 iphone 铃声音量设置为零。我的问题是我想恢复并且使用相同的代码只是更改音量级别不起作用。请提出适当的方法来做到这一点。
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];
我试图将 newvolumelevel 设置为 5 8 10 但它不起作用。
PS我知道它是一个私有框架和应用程序不会被批准。:)