mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2026-05-18 00:00:08 +08:00
ios: rename variables cameraPicker to cdvUIImagePickerController (#950)
* ios: Rename variables `cameraPicker` to `cdvUIImagePickerController` - Make clear, that `CDVUIImagePickerController` is used for these variables - When it's used as weak variable, it's renamed to `weakCDVUIImagePickerController` * fox(ios): Don't use `weak` in variable name - Rename `weakCDVUIImagePickerController` to `cdvUIImagePickerController` - It doesn't matter if it's a weak reference or not, it works like any other variable. The only reason `weakSelf` is a convention is because you need to explicitly create a variable to hold the weak reference.
This commit is contained in:
+18
-18
@@ -933,7 +933,7 @@ static NSString* MIME_JPEG = @"image/jpeg";
|
||||
|
||||
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
|
||||
{
|
||||
__weak CDVUIImagePickerController* cameraPicker = (CDVUIImagePickerController*)picker;
|
||||
__weak CDVUIImagePickerController* cdvUIImagePickerController = (CDVUIImagePickerController*)picker;
|
||||
__weak CDVCamera* weakSelf = self;
|
||||
|
||||
dispatch_block_t invoke = ^(void) {
|
||||
@@ -943,9 +943,9 @@ static NSString* MIME_JPEG = @"image/jpeg";
|
||||
|
||||
// Image selected
|
||||
if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
|
||||
[weakSelf resultForImage:cameraPicker.pictureOptions info:info completion:^(CDVPluginResult* res) {
|
||||
[weakSelf resultForImage:cdvUIImagePickerController.pictureOptions info:info completion:^(CDVPluginResult* res) {
|
||||
if (![self usesGeolocation] || picker.sourceType != UIImagePickerControllerSourceTypeCamera) {
|
||||
[weakSelf.commandDelegate sendPluginResult:res callbackId:cameraPicker.callbackId];
|
||||
[weakSelf.commandDelegate sendPluginResult:res callbackId:cdvUIImagePickerController.callbackId];
|
||||
weakSelf.hasPendingOperation = NO;
|
||||
weakSelf.cdvUIImagePickerController = nil;
|
||||
}
|
||||
@@ -954,13 +954,13 @@ static NSString* MIME_JPEG = @"image/jpeg";
|
||||
// Video selected
|
||||
} else {
|
||||
result = [weakSelf resultForVideo:info];
|
||||
[weakSelf.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId];
|
||||
[weakSelf.commandDelegate sendPluginResult:result callbackId:cdvUIImagePickerController.callbackId];
|
||||
weakSelf.hasPendingOperation = NO;
|
||||
weakSelf.cdvUIImagePickerController = nil;
|
||||
}
|
||||
};
|
||||
|
||||
[[cameraPicker presentingViewController] dismissViewControllerAnimated:YES completion:invoke];
|
||||
[[cdvUIImagePickerController presentingViewController] dismissViewControllerAnimated:YES completion:invoke];
|
||||
}
|
||||
|
||||
// older api calls newer didFinishPickingMediaWithInfo
|
||||
@@ -975,7 +975,7 @@ static NSString* MIME_JPEG = @"image/jpeg";
|
||||
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
|
||||
{
|
||||
__weak CDVUIImagePickerController* cameraPicker = (CDVUIImagePickerController*)picker;
|
||||
__weak CDVUIImagePickerController* cdvUIImagePickerController = (CDVUIImagePickerController*)picker;
|
||||
__weak CDVCamera* weakSelf = self;
|
||||
|
||||
dispatch_block_t invoke = ^ (void) {
|
||||
@@ -987,13 +987,13 @@ static NSString* MIME_JPEG = @"image/jpeg";
|
||||
}
|
||||
|
||||
|
||||
[weakSelf.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId];
|
||||
[weakSelf.commandDelegate sendPluginResult:result callbackId:cdvUIImagePickerController.callbackId];
|
||||
|
||||
weakSelf.hasPendingOperation = NO;
|
||||
weakSelf.cdvUIImagePickerController = nil;
|
||||
};
|
||||
|
||||
[[cameraPicker presentingViewController] dismissViewControllerAnimated:YES completion:invoke];
|
||||
[[cdvUIImagePickerController presentingViewController] dismissViewControllerAnimated:YES completion:invoke];
|
||||
}
|
||||
|
||||
#pragma mark CLLocationManager
|
||||
@@ -1198,24 +1198,24 @@ static NSString* MIME_JPEG = @"image/jpeg";
|
||||
|
||||
+ (instancetype)createFromPictureOptions:(CDVPictureOptions*)pictureOptions
|
||||
{
|
||||
CDVUIImagePickerController* cameraPicker = [[CDVUIImagePickerController alloc] init];
|
||||
cameraPicker.pictureOptions = pictureOptions;
|
||||
cameraPicker.sourceType = pictureOptions.sourceType;
|
||||
cameraPicker.allowsEditing = pictureOptions.allowsEditing;
|
||||
CDVUIImagePickerController* cdvUIImagePickerController = [[CDVUIImagePickerController alloc] init];
|
||||
cdvUIImagePickerController.pictureOptions = pictureOptions;
|
||||
cdvUIImagePickerController.sourceType = pictureOptions.sourceType;
|
||||
cdvUIImagePickerController.allowsEditing = pictureOptions.allowsEditing;
|
||||
|
||||
if (cameraPicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
||||
if (cdvUIImagePickerController.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
||||
// We only allow taking pictures (no video) in this API.
|
||||
cameraPicker.mediaTypes = @[(NSString*)kUTTypeImage];
|
||||
cdvUIImagePickerController.mediaTypes = @[(NSString*)kUTTypeImage];
|
||||
// We can only set the camera device if we're actually using the camera.
|
||||
cameraPicker.cameraDevice = pictureOptions.cameraDirection;
|
||||
cdvUIImagePickerController.cameraDevice = pictureOptions.cameraDirection;
|
||||
} else if (pictureOptions.mediaType == MediaTypeAll) {
|
||||
cameraPicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:cameraPicker.sourceType];
|
||||
cdvUIImagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:cdvUIImagePickerController.sourceType];
|
||||
} else {
|
||||
NSArray* mediaArray = @[(NSString*)(pictureOptions.mediaType == MediaTypeVideo ? kUTTypeMovie : kUTTypeImage)];
|
||||
cameraPicker.mediaTypes = mediaArray;
|
||||
cdvUIImagePickerController.mediaTypes = mediaArray;
|
||||
}
|
||||
|
||||
return cameraPicker;
|
||||
return cdvUIImagePickerController;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user