Fix build problem, save image on cache directory and return uri on response.

This commit is contained in:
Joao Fidelis 2018-01-23 10:36:00 -02:00
parent 310933edec
commit 9998c0f98a
4 changed files with 15 additions and 9 deletions

View File

@ -325,8 +325,8 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
float quality = [options[@"quality"] floatValue];
NSData *takenImageData = UIImageJPEGRepresentation(takenImage, quality);
// NSString *path = [RCTFileSystem generatePathInDirectory:[self.bridge.scopedModules.fileSystem.cachesDirectory stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
// response[@"uri"] = [RCTImageUtils writeImage:takenImageData toPath:path];
NSString *path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
response[@"uri"] = [RNImageUtils writeImage:takenImageData toPath:path];
response[@"width"] = @(takenImage.size.width);
response[@"height"] = @(takenImage.size.height);
@ -389,9 +389,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
[connection setVideoOrientation:[RNCameraUtils videoOrientationForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]];
dispatch_async(self.sessionQueue, ^{
// NSString *path = [RCTFileSystem generatePathInDirectory:[self.bridge.scopedModules.fileSystem.cachesDirectory stringByAppendingPathComponent:@"Camera"] withExtension:@".mov"];
// NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:path];
// [self.movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
NSString *path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingString:@"Camera"] withExtension:@".mov"];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:path];
[self.movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
self.videoRecordedResolve = resolve;
self.videoRecordedReject = reject;
});

View File

@ -12,7 +12,6 @@
@implementation RNCameraManager
RCT_EXPORT_MODULE(RNCameraManager);
//RCT_EXPORT_MODULE(RNCamera);
RCT_EXPORT_VIEW_PROPERTY(onCameraReady, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onMountError, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onBarCodeRead, RCTDirectEventBlock);
@ -168,10 +167,10 @@ RCT_REMAP_METHOD(takePicture,
#if TARGET_IPHONE_SIMULATOR
NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
float quality = [options[@"quality"] floatValue];
// NSString *path = [RCTFileSystem generatePathInDirectory:[self.bridge.scopedModules.fileSystem.cachesDirectory stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
NSString *path = [RNFileSystem generatePathInDirectory:[[RNFileSystem cacheDirectoryPath] stringByAppendingPathComponent:@"Camera"] withExtension:@".jpg"];
UIImage *generatedPhoto = [RNImageUtils generatePhotoOfSize:CGSizeMake(200, 200)];
NSData *photoData = UIImageJPEGRepresentation(generatedPhoto, quality);
// response[@"uri"] = [RCTImageUtils writeImage:photoData toPath:path];
response[@"uri"] = [RNImageUtils writeImage:photoData toPath:path];
response[@"width"] = @(generatedPhoto.size.width);
response[@"height"] = @(generatedPhoto.size.height);
if ([options[@"base64"] boolValue]) {
@ -223,7 +222,7 @@ RCT_REMAP_METHOD(record,
}];
}
RCT_REMAP_METHOD(stopRecording)
RCT_EXPORT_METHOD(stopRecording)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
RNCamera *view = nil;

View File

@ -11,6 +11,7 @@
+ (BOOL)ensureDirExistsWithPath:(NSString *)path;
+ (NSString *)generatePathInDirectory:(NSString *)directory withExtension:(NSString *)extension;
+ (NSString *)cacheDirectoryPath;
@end

View File

@ -30,5 +30,11 @@
return [directory stringByAppendingPathComponent:fileName];
}
+ (NSString *)cacheDirectoryPath
{
NSArray *array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
return [array objectAtIndex:0];
}
@end