cordova-screenshot icon indicating copy to clipboard operation
cordova-screenshot copied to clipboard

how to save images in Albums in iphone

Open Gowrilink opened this issue 9 years ago • 4 comments

Hi gitawego,

in android images save in pictures folde,But in iPhone screenshot images not appear in camera role (albums) how to save images in Camera albums in iPhone.Now i am using iPhone 5 ,cordova 3.5

Gowrilink avatar Dec 29 '14 07:12 Gowrilink

+1 for this. What's the best way on iPad / iPhone to export the pictures e.g. to Dropbox?

karladler avatar Sep 09 '15 14:09 karladler

Not sure if the awsner is still needed but I needed the screenshot to save in the Photos application on iOS. I managed to save my screenshot in the Photos application and appear in Camera Roll and My Photo Stream. I changed the code in the saveScreenshot() function in the Screenshot.m class. The image variable contains the screenshot which is just taken by your device. Instead of using the UIImageJPEGRepresentation() function and then write it to your device I used the UIImageWriteToSavedPhotosAlbum() function. This works like a charm for me!

  • (void)saveScreenshot:(CDVInvokedUrlCommand*)command { NSString *filename = [command.arguments objectAtIndex:2]; NSNumber *quality = [command.arguments objectAtIndex:1];

    NSString *path = [NSString stringWithFormat:@"%@.jpg",filename]; NSString *jpgPath = [NSTemporaryDirectory() stringByAppendingPathComponent:path];

    UIImage *image = [self getScreenshot]; UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

    //NSData *imageData = UIImageJPEGRepresentation(image); //[imageData writeToFile:jpgPath atomically:NO];

    CDVPluginResult* pluginResult = nil; NSDictionary *jsonObj = [ [NSDictionary alloc] initWithObjectsAndKeys : jpgPath, @"filePath", @"true", @"success", nil ];

    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj]; [self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]]; }

Merkane avatar Nov 11 '15 15:11 Merkane

What is the best way to use this? When changing the code as described in the comment above, my app will no longer compile. (Fails with "Check dependencies")

sqwk avatar Mar 24 '17 02:03 sqwk

Not sure if the awsner is still needed but I needed the screenshot to save in the Photos application on iOS. I managed to save my screenshot in the Photos application and appear in Camera Roll and My Photo Stream. I changed the code in the saveScreenshot() function in the Screenshot.m class. The image variable contains the screenshot which is just taken by your device. Instead of using the UIImageJPEGRepresentation() function and then write it to your device I used the UIImageWriteToSavedPhotosAlbum() function. This works like a charm for me!

  • (void)saveScreenshot:(CDVInvokedUrlCommand*)command { NSString *filename = [command.arguments objectAtIndex:2]; NSNumber *quality = [command.arguments objectAtIndex:1]; NSString *path = [NSString stringWithFormat:@"%@.jpg",filename]; NSString *jpgPath = [NSTemporaryDirectory() stringByAppendingPathComponent:path]; UIImage *image = [self getScreenshot]; UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //NSData imageData = UIImageJPEGRepresentation(image); //[imageData writeToFile:jpgPath atomically:NO]; CDVPluginResult pluginResult = nil; NSDictionary *jsonObj = [ [NSDictionary alloc] initWithObjectsAndKeys : jpgPath, @"filePath", @"true", @"success", nil ]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj]; [self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]]; }

My hero ! Five years later and it's work like a charm !

I've not succeed to add all of this code in my screenshot.m, but I just copied this line in bottom of line 37 "UIImage *image" :

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

Simple, no ? 😄

Hope it will help someone in the future 😉

PS : If Xcode thrown an error, you just have to restart it and it will be good !

palmthree-studio avatar Apr 09 '20 16:04 palmthree-studio