From 89954286eb9dcf60b47df75ad9cef983032e98bb Mon Sep 17 00:00:00 2001 From: Ran Greenberg Date: Wed, 28 Sep 2016 17:06:21 +0300 Subject: [PATCH] Fix an issue when there are photos in the photo gallery in a future date (the user manually set the time to the future). Now the camera will return the right photo taken. --- ios/lib/ReactNativeCameraKit/CKCamera.m | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.m b/ios/lib/ReactNativeCameraKit/CKCamera.m index d387638..94c05b9 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.m +++ b/ios/lib/ReactNativeCameraKit/CKCamera.m @@ -85,7 +85,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ @property (nonatomic) AVCaptureFlashMode flashMode; @property (nonatomic) CKCameraFocushMode focusMode; @property (nonatomic) CKCameraZoomMode zoomMode; -@property (nonatomic, strong) PHFetchOptions *fetchOptions; @property (nonatomic, strong) NSString* ratioOverlayString; @property (nonatomic, strong) UIColor *ratioOverlayColor; @@ -104,16 +103,16 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ } -(PHFetchOptions *)fetchOptions { - if (!_fetchOptions) { - PHFetchOptions *fetchOptions = [PHFetchOptions new]; - fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; - // iOS 9+ - if ([fetchOptions respondsToSelector:@selector(fetchLimit)]) { - fetchOptions.fetchLimit = 1; - } - _fetchOptions = fetchOptions; + + PHFetchOptions *fetchOptions = [PHFetchOptions new]; + fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; + fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d && creationDate <= %@",PHAssetMediaTypeImage, [NSDate date]]; + // iOS 9+ + if ([fetchOptions respondsToSelector:@selector(fetchLimit)]) { + fetchOptions.fetchLimit = 1; } - return _fetchOptions; + + return fetchOptions; } - (void)removeReactSubview:(UIView *)subview