Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 51093d0

Browse files
Merge pull request #23 from bmdelacruz/master
Fix "Ios return path" issue
2 parents d270bcb + ee4e96a commit 51093d0

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/ios/Base64ToGallery.m

+19-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command
6262
if(cameraRoll){
6363
// add the image to camera roll
6464
UIImage * savedImage = [UIImage imageWithContentsOfFile:imagePath];
65-
UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), nil);
65+
UIImageWriteToSavedPhotosAlbum(savedImage, self,
66+
@selector(thisImage:hasBeenSavedInPhotoAlbumWithError:onImagePath:),
67+
(void *) CFBridgingRetain(imagePath));
68+
} else {
69+
// send back the image path of the saved image
70+
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:imagePath];
71+
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
6672
}
6773

6874
}else{
@@ -79,14 +85,18 @@ - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command
7985
}];
8086
}
8187

82-
-(void)thisImage:(UIImage *)image hasBeenSavedInPhotoAlbumWithError:(NSError *)error usingContextInfo:(void*)ctxInfo{
83-
if (error) {
84-
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Error saving Image to Gallery, check Permissions"];
85-
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
86-
} else {
87-
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"Image Saved to Gallery"];
88-
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
88+
-(void)thisImage:(UIImage *)image hasBeenSavedInPhotoAlbumWithError:(NSError *)error onImagePath:(void*)bridgedImagePath{
89+
if (error) {
90+
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Error saving Image to Gallery, check Permissions"];
91+
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
92+
} else {
93+
// retrieve bridged image path and release it to get the image path
94+
NSString *imagePath = (NSString *) CFBridgingRelease(bridgedImagePath);
95+
96+
// send the image path back to the js callback
97+
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:imagePath];
98+
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
99+
}
89100
}
90-
}
91101

92102
@end

0 commit comments

Comments
 (0)