using AVSystemController in iPhone App

2019-07-20 19:08发布

I want to reduce the ringing volume of iPhone programmatically, I came to know that it is possible with AVSystemController, But I know, it is a private method. If I use it, will apple reject the app or please suggest me the alternative way

5条回答
贪生不怕死
2楼-- · 2019-07-20 19:36
- (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];
}  
查看更多
干净又极端
3楼-- · 2019-07-20 19:39

Using any kind of private method there is the change of Apple rejecting your app. Since the public iOS SDk does not allow you to change the ringer volume, you will not be able to this from your app.

查看更多
小情绪 Triste *
4楼-- · 2019-07-20 19:39

Possible yes, apple will reject it. Here is the link that will tell you how to do this.[link2

Update:

[[MPMusicPlayerController applicationMusicPlayer] setVolume:setvalue];

Check theselink link also. You cannot change the ringer volume programmatically.

查看更多
\"骚年 ilove
5楼-- · 2019-07-20 19:54

Try this code

float value = 0.5;//this should be between 0.0 to 1.0

[[MPMusicPlayerController applicationMusicPlayer] setVolume: value];
查看更多
劳资没心,怎么记你
6楼-- · 2019-07-20 20:02

you can use AVAudioPlayer and MPVolumeView for manage valume also please refer this link: How to implement a volume key shutter for iPhone?

查看更多
登录 后发表回答