我想以编程方式减少iPhone的铃声,我知道AVSystemController是可能的,但是我知道,这是一种 private 方法。如果我使用它,苹果会拒绝该应用程序还是请建议我其他方法

最佳答案

- (void) setSystemVolumeLevelTo:(float)newVolumeLevel
{
    Class avSystemControllerClass = NSClassFromString(@"AVSystemController");
    id avSystemControllerInstance = [avSystemControllerClass performSelector:@selector(sharedAVSystemController)];

    NSString *soundCategory = @"Ringtone";

    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];
}

09-27 03:27