You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/09/17 00:59:41 UTC

git commit: [CB-4847] iOS 7 microphone access requires user permission - if denied, CDVCapture, CDVSound does not handle it properly

Updated Branches:
  refs/heads/master 43a098252 -> a99ab1b4f


[CB-4847] iOS 7 microphone access requires user permission - if denied, CDVCapture, CDVSound does not handle it properly


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/commit/a99ab1b4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/a99ab1b4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/a99ab1b4

Branch: refs/heads/master
Commit: a99ab1b4f79df49b5bea34d52f68f4e6009f54ed
Parents: 43a0982
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Sep 16 15:59:43 2013 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Sep 16 15:59:43 2013 -0700

----------------------------------------------------------------------
 src/ios/CDVCapture.m | 54 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/a99ab1b4/src/ios/CDVCapture.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m
index 774c430..e14f248 100644
--- a/src/ios/CDVCapture.m
+++ b/src/ios/CDVCapture.m
@@ -721,25 +721,47 @@
         [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);
     }
 }