Skip to content
Permalink
Browse files
[CB-4847] iOS 7 microphone access requires user permission - if denie…
…d, CDVCapture, CDVSound does not handle it properly
  • Loading branch information
shazron committed Sep 17, 2013
1 parent 1dcba48 commit f87cec112972607fa68a6831e65f500ff182d74d
Showing 1 changed file with 38 additions and 16 deletions.
@@ -729,25 +729,47 @@ - (void)processButton:(id)sender
[self.recordButton setImage:stopRecordImage forState:UIControlStateNormal];
self.recordButton.accessibilityTraits &= ~[self accessibilityTraits];
[self.recordingView setHidden:NO];
NSError* error = nil;
[self.avSession setCategory:AVAudioSessionCategoryRecord error:&error];
[self.avSession setActive:YES error:&error];
if (error) {
// can't continue without active audio session
self.errorCode = CAPTURE_INTERNAL_ERR;
[self dismissAudioView:nil];
} else {
if (self.duration) {
self.isTimed = true;
[self.avRecorder recordForDuration:[duration doubleValue]];
__block NSError* error = nil;

void (^startRecording)(void) = ^{
[self.avSession setCategory:AVAudioSessionCategoryRecord error:&error];
[self.avSession setActive:YES error:&error];
if (error) {
// can't continue without active audio session
self.errorCode = CAPTURE_INTERNAL_ERR;
[self dismissAudioView:nil];
} else {
[self.avRecorder record];
if (self.duration) {
self.isTimed = true;
[self.avRecorder recordForDuration:[duration doubleValue]];
} else {
[self.avRecorder record];
}
[self.timerLabel setText:@"0.00"];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
self.doneButton.enabled = NO;
}
[self.timerLabel setText:@"0.00"];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
self.doneButton.enabled = NO;
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
};

SEL rrpSel = NSSelectorFromString(@"requestRecordPermission:");
if ([self.avSession respondsToSelector:rrpSel])
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.avSession performSelector:rrpSel withObject:^(BOOL granted){
if (granted) {
startRecording();
} else {
NSLog(@"Error creating audio session, microphone permission denied.");
self.errorCode = CAPTURE_INTERNAL_ERR;
[self dismissAudioView:nil];
}
}];
#pragma clang diagnostic pop
} else {
startRecording();
}
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
}
}

0 comments on commit f87cec1

Please sign in to comment.