mirror of
https://github.com/status-im/react-native-camera.git
synced 2025-02-24 01:38:18 +00:00
Merge pull request #151 from christopherdro/capture-temp
Add option to store captures in temp directory
This commit is contained in:
commit
114476de03
@ -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) {
|
||||
|
@ -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)]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user