From 2c56fe7a764a301238facb72b351ef5702882f19 Mon Sep 17 00:00:00 2001 From: Ran Greenberg Date: Fri, 1 Jul 2016 19:49:41 +0300 Subject: [PATCH] add local identifier to the image dictionary result after capture a photo --- ios/lib/ReactNativeCameraKit/CKCamera.m | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.m b/ios/lib/ReactNativeCameraKit/CKCamera.m index 0775797..04bc942 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.m +++ b/ios/lib/ReactNativeCameraKit/CKCamera.m @@ -81,7 +81,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ @property (nonatomic) AVCaptureFlashMode flashMode; @property (nonatomic) CKCameraFocushMode focusMode; @property (nonatomic) CKCameraZoomMode zoomMode; - +@property (nonatomic, strong) PHFetchOptions *fetchOptions; @end @@ -94,6 +94,15 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ NSLog(@"dealloc"); } +-(PHFetchOptions *)fetchOptions { + if (!_fetchOptions) { + PHFetchOptions *fetchOptions = [PHFetchOptions new]; + fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; + fetchOptions.fetchLimit = 1; + _fetchOptions = fetchOptions; + } + return _fetchOptions; +} - (void)removeReactSubview:(UIView *)subview { @@ -424,15 +433,22 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ imageInfoDict[@"uri"] = temporaryFileURL.description; imageInfoDict[@"name"] = temporaryFileURL.lastPathComponent; } - imageInfoDict[@"size"] = [NSNumber numberWithInteger:imageData.length]; - - if (shouldSaveToCameraRoll) { [self saveImageToCameraRoll:imageData temporaryFileURL:temporaryFileURL]; } + + PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:self.fetchOptions]; + PHAsset *lastImageAsset = [fetchResult firstObject]; + + if (lastImageAsset.localIdentifier) { + imageInfoDict[@"id"] = lastImageAsset.localIdentifier; + } + + + if (block) { block(imageInfoDict); } @@ -550,7 +566,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ NSLog( @"Error occured while writing image data to a temporary file: %@", error ); } else { - NSLog(@"YOU ROCK!"); + NSLog(@"Image Saved - YOU ROCK!"); } return temporaryFileURL; } @@ -590,10 +606,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ }]; - - [self startFocusViewTimer]; - }