From 9998c0f98a412aff3d6612364efd6b0930ac9b06 Mon Sep 17 00:00:00 2001 From: Joao Fidelis Date: Tue, 23 Jan 2018 10:36:00 -0200 Subject: [PATCH] Fix build problem, save image on cache directory and return uri on response. --- ios/RN/RNCamera.m | 10 +++++----- ios/RN/RNCameraManager.m | 7 +++---- ios/RN/RNFileSystem.h | 1 + ios/RN/RNFileSystem.m | 6 ++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ios/RN/RNCamera.m b/ios/RN/RNCamera.m index f49d8ec..e242d33 100644 --- a/ios/RN/RNCamera.m +++ b/ios/RN/RNCamera.m @@ -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; }); diff --git a/ios/RN/RNCameraManager.m b/ios/RN/RNCameraManager.m index d69c59b..7da8cb0 100644 --- a/ios/RN/RNCameraManager.m +++ b/ios/RN/RNCameraManager.m @@ -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 *viewRegistry) { RNCamera *view = nil; diff --git a/ios/RN/RNFileSystem.h b/ios/RN/RNFileSystem.h index 40a8d96..1b277d9 100644 --- a/ios/RN/RNFileSystem.h +++ b/ios/RN/RNFileSystem.h @@ -11,6 +11,7 @@ + (BOOL)ensureDirExistsWithPath:(NSString *)path; + (NSString *)generatePathInDirectory:(NSString *)directory withExtension:(NSString *)extension; ++ (NSString *)cacheDirectoryPath; @end diff --git a/ios/RN/RNFileSystem.m b/ios/RN/RNFileSystem.m index f5b47fc..106f221 100644 --- a/ios/RN/RNFileSystem.m +++ b/ios/RN/RNFileSystem.m @@ -30,5 +30,11 @@ return [directory stringByAppendingPathComponent:fileName]; } ++ (NSString *)cacheDirectoryPath +{ + NSArray *array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + return [array objectAtIndex:0]; +} + @end