Hi!
I've detected an issue that I'm not sure if I'm doing something wrong or if it's a bug in iOS.
When I am playing a sound and activate the device's proximity sensor the system's volume indicator is no longer displayed on screen when using the volume keys.
I've created a simple app that loops a small mp3 and at the same time activates the proximity sensor.
Before I cover the sensor for the first time if I press the volume keys I see the system volume indicator as expected.
If I then cover the sensor and uncover it again and try to use the volume keys they work (i.e. the sound volume increases or decreases) but no visual indication is given.
Stopping the sound, killing and restaring the app don't fix the issue, most times I have to reboot the device in order for the volume indicator to appear on my app again.
This seems to be an issue with iOS, but I've checked other apps that don't exibith this behaviour, like WhatsApp, for example.
Do I need to configure something in the audio session to be able to use the proximity sensor?
Here is my sample code:
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (!self.audioPlayer) {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"]];
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
self.audioPlayer.numberOfLoops = -1;
}
}
- (IBAction)btnPlayAction:(id)sender
{
if (!self.audioPlayer.isPlaying) {
[self.audioPlayer prepareToPlay];
[self.audioPlayer play];
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
}
}
- (IBAction)btnStopAction:(id)sender
{
if (self.audioPlayer.isPlaying) {
[self.audioPlayer stop];
[UIDevice currentDevice].proximityMonitoringEnabled = NO;
}
}
@end