Updated Branches: refs/heads/2.9.x 5201cad46 -> 40ff9826a
CB-5189 - ios - Backport of v2.9.1 from CB-4847 (Media Capture only) Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/40ff9826 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/40ff9826 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/40ff9826 Branch: refs/heads/2.9.x Commit: 40ff9826a87aff4abc82d944d2c9034eb6af0a9c Parents: 5201cad Author: Shazron Abdullah <[email protected]> Authored: Wed Oct 23 17:34:33 2013 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Wed Oct 23 17:34:33 2013 -0700 ---------------------------------------------------------------------- CordovaLib/Classes/CDVCapture.h | 2 +- CordovaLib/Classes/CDVCapture.m | 75 ++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/40ff9826/CordovaLib/Classes/CDVCapture.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVCapture.h b/CordovaLib/Classes/CDVCapture.h index afb82b4..2cd8db8 100644 --- a/CordovaLib/Classes/CDVCapture.h +++ b/CordovaLib/Classes/CDVCapture.h @@ -20,7 +20,7 @@ #import <Foundation/Foundation.h> #import <MobileCoreServices/MobileCoreServices.h> #import <AVFoundation/AVFoundation.h> -#import "CDVPlugin.h" +#import <Cordova/CDVPlugin.h> #import "CDVFile.h" enum CDVCaptureError { http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/40ff9826/CordovaLib/Classes/CDVCapture.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVCapture.m b/CordovaLib/Classes/CDVCapture.m index 884702d..ffffc2c 100644 --- a/CordovaLib/Classes/CDVCapture.m +++ b/CordovaLib/Classes/CDVCapture.m @@ -18,8 +18,8 @@ */ #import "CDVCapture.h" -#import "CDVJSON.h" -#import "CDVAvailability.h" +#import <Cordova/CDVJSON.h> +#import <Cordova/CDVAvailability.h> #define kW3CMediaFormatHeight @"height" #define kW3CMediaFormatWidth @"width" @@ -88,9 +88,11 @@ self.inUse = YES; - if ([self.viewController respondsToSelector:@selector(presentViewController:::)]) { + SEL selector = NSSelectorFromString(@"presentViewController:animated:completion:"); + if ([self.viewController respondsToSelector:selector]) { [self.viewController presentViewController:navController animated:YES completion:nil]; } else { + // deprecated as of iOS >= 6.0 [self.viewController presentModalViewController:navController animated:YES]; } } @@ -139,9 +141,11 @@ // CDVImagePicker specific property pickerController.callbackId = callbackId; - if ([self.viewController respondsToSelector:@selector(presentViewController:::)]) { + SEL selector = NSSelectorFromString(@"presentViewController:animated:completion:"); + if ([self.viewController respondsToSelector:selector]) { [self.viewController presentViewController:pickerController animated:YES completion:nil]; } else { + // deprecated as of iOS >= 6.0 [self.viewController presentModalViewController:pickerController animated:YES]; } } @@ -255,9 +259,11 @@ // CDVImagePicker specific property pickerController.callbackId = callbackId; - if ([self.viewController respondsToSelector:@selector(presentViewController:::)]) { + SEL selector = NSSelectorFromString(@"presentViewController:animated:completion:"); + if ([self.viewController respondsToSelector:selector]) { [self.viewController presentViewController:pickerController animated:YES completion:nil]; } else { + // deprecated as of iOS >= 6.0 [self.viewController presentModalViewController:pickerController animated:YES]; } } @@ -615,7 +621,12 @@ // timerLabel.autoresizingMask = reSizeMask; [self.timerLabel setBackgroundColor:[UIColor clearColor]]; [self.timerLabel setTextColor:[UIColor whiteColor]]; +#ifdef __IPHONE_6_0 + [self.timerLabel setTextAlignment:NSTextAlignmentCenter]; +#else + // for iOS SDK < 6.0 [self.timerLabel setTextAlignment:UITextAlignmentCenter]; +#endif [self.timerLabel setText:@"0:00"]; [self.timerLabel setAccessibilityHint:NSLocalizedString(@"recorded time in minutes and seconds", nil)]; self.timerLabel.accessibilityTraits |= UIAccessibilityTraitUpdatesFrequently; @@ -718,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); } }
