以编程方式将iphone置于静音或振动模式?

时间:2015-01-27 17:33:14

标签: ios objective-c

我想将iPhone中的音量完全降低到0.而且我想知道有没有办法以编程方式将iPhone变为振动模式。 我做了一些工作,因为我不能完全将音量设为0.我在调用[self setSystemVolumeLevelTo:0]时将音量设为1。帮助我们......

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

0 个答案:

没有答案