diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m index f2fe258c..24e111f4 100644 --- a/src/ios/CDVCapture.m +++ b/src/ios/CDVCapture.m @@ -311,23 +311,27 @@ - (BOOL)hasCameraAccess - (void)showPermissionsAlert { - __weak CDVCapture* weakSelf = self; - dispatch_async(dispatch_get_main_queue(), ^{ - [[[UIAlertView alloc] initWithTitle:[[NSBundle mainBundle] - objectForInfoDictionaryKey:@"CFBundleDisplayName"] - message:NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.", nil) - delegate:weakSelf - cancelButtonTitle:NSLocalizedString(@"OK", nil) - otherButtonTitles:NSLocalizedString(@"Settings", nil), nil] show]; - }); -} - -- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"] + message:NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.", nil) + preferredStyle:UIAlertControllerStyleAlert]; + [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + [self returnNoPermissionError]; + }]]; + [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Settings", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]options:@{} completionHandler:nil]; + [self returnNoPermissionError]; + }]]; + [self.viewController presentViewController:alertController animated:YES completion:^{}]; +} + +- (void)returnNoPermissionError { - if (buttonIndex == 1) { - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; - } - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_PERMISSION_DENIED]; [[pickerController presentingViewController] dismissViewControllerAnimated:YES completion:nil]; @@ -588,19 +592,11 @@ - (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker @implementation CDVAudioNavigationController -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { // delegate to CVDAudioRecorderViewController return [self.topViewController supportedInterfaceOrientations]; } -#else -- (NSUInteger)supportedInterfaceOrientations -{ - // delegate to CVDAudioRecorderViewController - return [self.topViewController supportedInterfaceOrientations]; -} -#endif @end @@ -654,7 +650,7 @@ - (void)loadView } // create view and display - CGRect viewRect = [[UIScreen mainScreen] applicationFrame]; + CGRect viewRect = [[UIScreen mainScreen] bounds]; UIView* tmp = [[UIView alloc] initWithFrame:viewRect]; // make backgrounds @@ -696,12 +692,7 @@ - (void)loadView // 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:PluginLocalizedString(captureCommand, @"recorded time in minutes and seconds", nil)]; self.timerLabel.accessibilityTraits |= UIAccessibilityTraitUpdatesFrequently; @@ -776,7 +767,6 @@ - (void)viewDidLoad } } -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { UIInterfaceOrientationMask orientation = UIInterfaceOrientationMaskPortrait; @@ -785,22 +775,6 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown); return orientation; } -#else -- (NSUInteger)supportedInterfaceOrientations -{ - NSUInteger orientation = UIInterfaceOrientationMaskPortrait; // must support portrait - NSUInteger supported = [captureCommand.viewController supportedInterfaceOrientations]; - - orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown); - return orientation; -} -#endif - -- (void)viewDidUnload -{ - [self setView:nil]; - [self.captureCommand setInUse:NO]; -} - (void)processButton:(id)sender { @@ -828,7 +802,7 @@ - (void)processButton:(id)sender } else { if (weakSelf.duration) { weakSelf.isTimed = true; - [weakSelf.avRecorder recordForDuration:[duration doubleValue]]; + [weakSelf.avRecorder recordForDuration:[weakSelf.duration doubleValue]]; } else { [weakSelf.avRecorder record]; } @@ -882,7 +856,7 @@ - (void)stopRecordingCleanup //BOOL isUIAccessibilityAnnouncementNotification = (&UIAccessibilityAnnouncementNotification != NULL); if (UIAccessibilityAnnouncementNotification) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 500ull * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{ - UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, PluginLocalizedString(captureCommand, @"timed recording complete", nil)); + UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, PluginLocalizedString(self->captureCommand, @"timed recording complete", nil)); }); } } else { @@ -908,10 +882,6 @@ - (void)dismissAudioView:(id)sender UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); // return result [self.captureCommand.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; - - if (IsAtLeastiOSVersion(@"7.0")) { - [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; - } } - (void)updateTime @@ -962,18 +932,4 @@ - (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder*)recorder error:(NSErr [self dismissAudioView:nil]; } -- (UIStatusBarStyle)preferredStatusBarStyle -{ - return UIStatusBarStyleDefault; -} - -- (void)viewWillAppear:(BOOL)animated -{ - if (IsAtLeastiOSVersion(@"7.0")) { - [[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]]; - } - - [super viewWillAppear:animated]; -} - @end