Unable to use volume button to mute sound on iOS7

I recently migrated my VoIP application to iOS7, and there still remains an open error that I cannot understand.

When calling VoIP in iOS6, you can press the physical volume button to decrease the volume down to zero.

Now, in iOS7, I can only lower the sound to the last step to zero, which means that the volume cannot be turned off.

I suspect that this is on the iOS7 side, since I have no problem with the same IPA on the iOS6 device.

Does anyone know what?

+6
source share
3 answers

Same problem with my VoIP application ...

My solution: After everything is configured, set the category to Play,

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 

Then return it to PlayAndRecord,

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 

This works for me, hope this helps someone who is facing the same problem.

+2
source

A bit old question, but I also needed to resolve the Gui13 question / comment:

We do not use any control in our application, all volumetric interactions are based on volume buttons. So I could implement this, but I need a way to bind it to the volume buttons. Is it possible?

Apple recommends using MPVolumeView , so I came up with the following:

 MPVolumeView *volumeView = [MPVolumeView new]; [self.view addSubview:volumeView]; 

and then:

 __block UISlider *volumeSlider = nil; [[volumeView subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[UISlider class]]) { volumeSlider = obj; *stop = YES; } }]; [volumeSlider addTarget:self action:@selector(handleVolumeChanged:) forControlEvents:UIControlEventValueChanged]; 

with:

 - (void)handleVolumeChanged:(id)sender { NSLog(@"%s - %f", __PRETTY_FUNCTION__, ((UISlider *)sender).value); } 

The code [MPVolumeView new] higher than inits MPVolumeView without a frame, so it does not appear in our self.view , where it was added as a preview, but it is important that it be added!

You can also run MPVolumeView with the code:

 MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:self.view.frame]; volumeView.showsRouteButton = NO; volumeView.showsVolumeSlider = NO; [self.view addSubview:volumeView]; 

which will also launch an empty MPVolumeView (i.e. without RouteButton and VolumeSlider).

Interestingly, the UISlider subview (actually MPVolumeSlider , a subclass of UISlider ) will still be found in enumerateObjectsUsingBlock above.

This approach is also interesting in that you can save a link to volumeSlider and use it later to set the volume from code or your custom control:

Initialize and add to your view:

 MPVolumeView *volumeView = [MPVolumeView new]; volumeView.showsRouteButton = NO; volumeView.showsVolumeSlider = NO; [self.view addSubview:volumeView]; 

Find and save the link to UISlider :

 __weak __typeof(self)weakSelf = self; [[volumeView subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[UISlider class]]) { __strong __typeof(weakSelf)strongSelf = weakSelf; strongSelf.volumeSlider = obj; *stop = YES; } }]; 

Add the target action for UIControlEventValueChanged :

 [self.volumeSlider addTarget:self action:@selector(handleVolumeChanged:) forControlEvents:UIControlEventValueChanged]; 

And then update your custom control when the volume has been changed (i.e. using hardware volume controls):

 - (void)handleVolumeChanged:(id)sender { NSLog(@"%s - %f", __PRETTY_FUNCTION__, self.volumeSlider.value); self.myCustomVolumeSliderView.value = self.volumeSlider.value; } 

and:

 - (IBAction)myCustomVolumeSliderViewValueChanged:(id)sender { NSLog(@"set volume to: %f", self.myCustomVolumeSliderView.value); self.volumeSlider.value = self.myCustomVolumeSliderView.value; } 

Hope this helps someone (and that Apple is not removing MPVolumeSlider from MPVolumeView).

+3
source

You must use applicationMusicPlayer instead of iPodMusicPlayer to install the system volume:

 #import <MediaPlayer/MediaPlayer.h> musicPlayer = [MPMusicPlayerController applicationMusicPlayer]; musicPlayer.volume = 1; // max volume musicPlayer.volume = 0; // min volume (mute) musicPlayer.volume = 0.0625; // 1 bar on the overlay volume display 

Apple suggests that they know every way that a volume needs to be managed.

There are, in fact, cases when we want to change the way we manage the volume without forcing the user to have a volume slider on the screen (alarm clocks and media players immediately come to mind). Yuu can take the link

https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html

http://ios-blog.co.uk/tutorials/controlling-system-output-volume-with-the-mpvolumeview-class-part-one/

+2
source

Source: https://habr.com/ru/post/956092/


All Articles