CB-13813: (iOS) Remove old iOS code (#381)

This commit is contained in:
jcesarmobile 2018-12-04 12:21:39 +01:00 committed by GitHub
parent cd72047dfc
commit ce77aab010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -139,11 +139,9 @@ static NSString* toBase64(NSData* data) {
- (void)takePicture:(CDVInvokedUrlCommand*)command - (void)takePicture:(CDVInvokedUrlCommand*)command
{ {
self.hasPendingOperation = YES; self.hasPendingOperation = YES;
__weak CDVCamera* weakSelf = self; __weak CDVCamera* weakSelf = self;
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command]; CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command];
pictureOptions.popoverSupported = [weakSelf popoverSupported]; pictureOptions.popoverSupported = [weakSelf popoverSupported];
pictureOptions.usesGeolocation = [weakSelf usesGeolocation]; pictureOptions.usesGeolocation = [weakSelf usesGeolocation];
@ -158,82 +156,72 @@ static NSString* toBase64(NSData* data) {
} }
// Validate the app has permission to access the camera // Validate the app has permission to access the camera
if (pictureOptions.sourceType == UIImagePickerControllerSourceTypeCamera && [AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)]) { if (pictureOptions.sourceType == UIImagePickerControllerSourceTypeCamera) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
if (authStatus == AVAuthorizationStatusDenied || {
authStatus == AVAuthorizationStatusRestricted) { if(!granted)
// If iOS 8+, offer a link to the Settings app {
#pragma clang diagnostic push // Denied; show an alert
#pragma clang diagnostic ignored "-Wtautological-pointer-compare" dispatch_async(dispatch_get_main_queue(), ^{
NSString* settingsButton = (&UIApplicationOpenSettingsURLString != NULL) 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];
? NSLocalizedString(@"Settings", nil) [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
: nil; [weakSelf sendNoPermissionResult:command.callbackId];
#pragma clang diagnostic pop }]];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// Denied; show an alert [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf sendNoPermissionResult:command.callbackId];
[[[UIAlertView alloc] initWithTitle:[[NSBundle mainBundle] }]];
objectForInfoDictionaryKey:@"CFBundleDisplayName"] [weakSelf.viewController presentViewController:alertController animated:YES completion:nil];
message:NSLocalizedString(@"Access to the camera has been prohibited; please enable it in the Settings app to continue.", nil) });
delegate:weakSelf } else {
cancelButtonTitle:NSLocalizedString(@"OK", nil) [weakSelf showCameraPicker:command.callbackId withOptions:pictureOptions];
otherButtonTitles:settingsButton, nil] show]; }
}); }];
} } else {
[weakSelf showCameraPicker:command.callbackId withOptions:pictureOptions];
} }
CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
weakSelf.pickerController = cameraPicker;
cameraPicker.delegate = weakSelf;
cameraPicker.callbackId = command.callbackId;
// we need to capture this state for memory warnings that dealloc this object
cameraPicker.webView = weakSelf.webView;
// Perform UI operations on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// If a popover is already open, close it; we only want one at a time.
if (([[weakSelf pickerController] pickerPopoverController] != nil) && [[[weakSelf pickerController] pickerPopoverController] isPopoverVisible]) {
[[[weakSelf pickerController] pickerPopoverController] dismissPopoverAnimated:YES];
[[[weakSelf pickerController] pickerPopoverController] setDelegate:nil];
[[weakSelf pickerController] setPickerPopoverController:nil];
}
if ([weakSelf popoverSupported] && (pictureOptions.sourceType != UIImagePickerControllerSourceTypeCamera)) {
if (cameraPicker.pickerPopoverController == nil) {
cameraPicker.pickerPopoverController = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController:cameraPicker];
}
[weakSelf displayPopover:pictureOptions.popoverOptions];
weakSelf.hasPendingOperation = NO;
} else {
cameraPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
[weakSelf.viewController presentViewController:cameraPicker animated:YES completion:^{
weakSelf.hasPendingOperation = NO;
}];
}
});
}]; }];
} }
// Delegate for camera permission UIAlertView - (void)showCameraPicker:(NSString*)callbackId withOptions:(CDVPictureOptions *) pictureOptions
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ {
// If Settings button (on iOS 8), open the settings app CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
if (buttonIndex == 1) { self.pickerController = cameraPicker;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-pointer-compare" cameraPicker.delegate = self;
if (&UIApplicationOpenSettingsURLString != NULL) { cameraPicker.callbackId = callbackId;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; // we need to capture this state for memory warnings that dealloc this object
cameraPicker.webView = self.webView;
// Perform UI operations on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// If a popover is already open, close it; we only want one at a time.
if (([[self pickerController] pickerPopoverController] != nil) && [[[self pickerController] pickerPopoverController] isPopoverVisible]) {
[[[self pickerController] pickerPopoverController] dismissPopoverAnimated:YES];
[[[self pickerController] pickerPopoverController] setDelegate:nil];
[[self pickerController] setPickerPopoverController:nil];
} }
#pragma clang diagnostic pop
}
// Dismiss the view if ([self popoverSupported] && (pictureOptions.sourceType != UIImagePickerControllerSourceTypeCamera)) {
[[self.pickerController presentingViewController] dismissViewControllerAnimated:YES completion:nil]; if (cameraPicker.pickerPopoverController == nil) {
cameraPicker.pickerPopoverController = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController:cameraPicker];
}
[self displayPopover:pictureOptions.popoverOptions];
self.hasPendingOperation = NO;
} else {
cameraPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self.viewController presentViewController:cameraPicker animated:YES completion:^{
self.hasPendingOperation = NO;
}];
}
});
}
- (void)sendNoPermissionResult:(NSString*)callbackId
{
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"has no access to camera"]; // error callback expects string ATM CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"has no access to camera"]; // error callback expects string ATM
[self.commandDelegate sendPluginResult:result callbackId:self.pickerController.callbackId]; [self.commandDelegate sendPluginResult:result callbackId:callbackId];
self.hasPendingOperation = NO; self.hasPendingOperation = NO;
self.pickerController = nil; self.pickerController = nil;