using AVSystemController in iPhone App

萝らか妹 提交于 2020-01-15 06:09:48

问题


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


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



回答2:


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.




回答3:


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.




回答4:


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




回答5:


Try this code

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

[[MPMusicPlayerController applicationMusicPlayer] setVolume: value];


来源:https://stackoverflow.com/questions/21157137/using-avsystemcontroller-in-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!