Merge pull request #151 from christopherdro/capture-temp

Add option to store captures in temp directory
This commit is contained in:
Loch Wansbrough 2016-01-15 12:10:22 -08:00
commit 114476de03
2 changed files with 39 additions and 15 deletions

View File

@ -17,7 +17,8 @@ typedef NS_ENUM(NSInteger, RCTCameraCaptureMode) {
typedef NS_ENUM(NSInteger, RCTCameraCaptureTarget) {
RCTCameraCaptureTargetMemory = 0,
RCTCameraCaptureTargetDisk = 1,
RCTCameraCaptureTargetCameraRoll = 2
RCTCameraCaptureTargetTemp = 2,
RCTCameraCaptureTargetCameraRoll = 3
};
typedef NS_ENUM(NSInteger, RCTCameraOrientation) {

View File

@ -65,6 +65,7 @@ RCT_EXPORT_VIEW_PROPERTY(torchMode, NSInteger);
@"CaptureTarget": @{
@"memory": @(RCTCameraCaptureTargetMemory),
@"disk": @(RCTCameraCaptureTargetDisk),
@"temp": @(RCTCameraCaptureTargetTemp),
@"cameraRoll": @(RCTCameraCaptureTargetCameraRoll)
},
@"Orientation": @{
@ -459,6 +460,14 @@ RCT_EXPORT_METHOD(stopCapture) {
responseString = fullPath;
}
else if (target == RCTCameraCaptureTargetTemp) {
NSString *fileName = [[NSProcessInfo processInfo] globallyUniqueString];
NSString *fullPath = [NSString stringWithFormat:@"%@%@.jpg", NSTemporaryDirectory(), fileName];
[imageData writeToFile:fullPath atomically:YES];
responseString = fullPath;
}
else if (target == RCTCameraCaptureTargetCameraRoll) {
[[[ALAssetsLibrary alloc] init] writeImageDataToSavedPhotosAlbum:imageData metadata:metadata completionBlock:^(NSURL* url, NSError* error) {
if (error == nil) {
@ -591,6 +600,20 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
}
self.videoCallback(@[[NSNull null], fullPath]);
}
else if (self.videoTarget == RCTCameraCaptureTargetTemp) {
NSString *fileName = [[NSProcessInfo processInfo] globallyUniqueString];
NSString *fullPath = [NSString stringWithFormat:@"%@%@.mov", NSTemporaryDirectory(), fileName];
NSFileManager * fileManager = [NSFileManager defaultManager];
NSError * error = nil;
//copying destination
if (!([fileManager copyItemAtPath:[outputFileURL path] toPath:fullPath error:&error])) {
self.videoCallback(@[RCTMakeError(error.description, nil, nil)]);
return;
}
self.videoCallback(@[[NSNull null], fullPath]);
}
else {
self.videoCallback(@[RCTMakeError(@"Target not supported", nil, nil)]);
}