cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject git commit: [CB-4847] iOS 7 microphone access requires user permission - if denied, CDVCapture, CDVSound does not handle it properly
Date Tue, 17 Sep 2013 00:25:18 GMT
Updated Branches:
  refs/heads/dev 1dcba489e -> f87cec112


[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/f87cec11
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/f87cec11
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/f87cec11

Branch: refs/heads/dev
Commit: f87cec112972607fa68a6831e65f500ff182d74d
Parents: 1dcba48
Author: Shazron Abdullah <shazron@apache.org>
Authored: Mon Sep 16 15:59:43 2013 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Mon Sep 16 17:25:08 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/f87cec11/src/ios/CDVCapture.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m
index b160660..3df4217 100644
--- a/src/ios/CDVCapture.m
+++ b/src/ios/CDVCapture.m
@@ -729,25 +729,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);
     }
 }
 


Mime
View raw message