Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] add saveToGallery param on iOS for captureVideo #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ios/CDVCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ typedef NSUInteger CDVCaptureError;
{
CDVImagePicker* pickerController;
BOOL inUse;
BOOL saveToGallery;
}
@property BOOL inUse;
@property BOOL saveToGallery;
- (void)captureAudio:(CDVInvokedUrlCommand*)command;
- (void)captureImage:(CDVInvokedUrlCommand*)command;
- (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId;
Expand Down
26 changes: 18 additions & 8 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ - (void)viewWillAppear:(BOOL)animated {

@implementation CDVCapture
@synthesize inUse;
@synthesize saveToGallery;

- (void)pluginInitialize
{
Expand Down Expand Up @@ -220,6 +221,14 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
options = [NSDictionary dictionary];
}

// option to save video to gallery or not
NSNumber* saveToGallery = [options objectForKey:@"saveToGallery"];
if([saveToGallery intValue] == 1) {
self.saveToGallery = YES;
} else {
self.saveToGallery = NO;
}

// options could contain limit, duration and mode
// taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property
NSNumber* duration = [options objectForKey:@"duration"];
Expand Down Expand Up @@ -280,14 +289,15 @@ - (void)captureVideo:(CDVInvokedUrlCommand*)command
- (CDVPluginResult*)processVideo:(NSString*)moviePath forCallbackId:(NSString*)callbackId
{
// save the movie to photo album (only avail as of iOS 3.1)

/* don't need, it should automatically get saved
NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath));
if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) {
NSLog(@"try to save movie");
UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil);
NSLog(@"finished saving movie");
}*/
if(self.saveToGallery == YES) {
NSLog(@"can save %@: %d ?", moviePath, UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath));
if (&UIVideoAtPathIsCompatibleWithSavedPhotosAlbum != NULL && UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) == YES) {
NSLog(@"try to save movie");
UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil);
NSLog(@"finished saving movie");
}
}

// create MediaFile object
NSDictionary* fileDict = [self getMediaDictionaryFromPath:moviePath ofType:nil];
NSArray* fileArray = [NSArray arrayWithObject:fileDict];
Expand Down