Repository: cordova-plugin-camera Updated Branches: refs/heads/master 036cdfdeb -> 63ac782b3
CB-8863 correct block usage for async calls Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/7f3a0a54 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/7f3a0a54 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/7f3a0a54 Branch: refs/heads/master Commit: 7f3a0a5483322a76e9121bda18f36ec84566aeab Parents: 036cdfd Author: Jesse MacFadyen <[email protected]> Authored: Tue Nov 17 16:37:45 2015 -0800 Committer: Jesse MacFadyen <[email protected]> Committed: Tue Nov 17 16:37:45 2015 -0800 ---------------------------------------------------------------------- src/ios/CDVCamera.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/7f3a0a54/src/ios/CDVCamera.m ---------------------------------------------------------------------- diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index ce40b0b..d5d3ba4 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -109,12 +109,14 @@ static NSString* toBase64(NSData* data) { - (NSURL*) urlTransformer:(NSURL*)url { NSURL* urlToTransform = url; + __weak CDVCamera* weakSelf = self; // for backwards compatibility - we check if this property is there SEL sel = NSSelectorFromString(@"urlTransformer"); if ([self.commandDelegate respondsToSelector:sel]) { + // grab the block from the commandDelegate - NSURL* (^urlTransformer)(NSURL*) = ((id(*)(id, SEL))objc_msgSend)(self.commandDelegate, sel); + NSURL* (^urlTransformer)(NSURL*) = ((id(*)(id, SEL))objc_msgSend)(weakSelf.commandDelegate, sel); // if block is not null, we call it if (urlTransformer) { urlToTransform = urlTransformer(url); @@ -172,7 +174,7 @@ static NSString* toBase64(NSData* data) { [[[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:self + delegate:weakSelf cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:settingsButton, nil] show]; }); @@ -511,14 +513,14 @@ static NSString* toBase64(NSData* data) { NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) { - [self resultForImage:cameraPicker.pictureOptions info:info completion:^(CDVPluginResult* res) { + [weakSelf resultForImage:cameraPicker.pictureOptions info:info completion:^(CDVPluginResult* res) { [weakSelf.commandDelegate sendPluginResult:res callbackId:cameraPicker.callbackId]; weakSelf.hasPendingOperation = NO; weakSelf.pickerController = nil; }]; } else { - result = [self resultForVideo:info]; + result = [weakSelf resultForVideo:info]; [weakSelf.commandDelegate sendPluginResult:result callbackId:cameraPicker.callbackId]; weakSelf.hasPendingOperation = NO; weakSelf.pickerController = nil; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
