@@ -949,33 +949,46 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
949
949
path = [RNFileSystem generatePathInDirectory: [[RNFileSystem cacheDirectoryPath ] stringByAppendingPathComponent: @" Camera" ] withExtension: imageExtension];
950
950
}
951
951
952
+ bool success = YES ;
953
+
952
954
if (![options[@" doNotSave" ] boolValue ]) {
953
- response[@" uri" ] = [RNImageUtils writeImage: destData toPath: path];
955
+ NSString * pathRes = [RNImageUtils writeImage: destData toPath: path];
956
+ if (!pathRes) {
957
+ reject (@" E_IMAGE_CAPTURE_FAILED" , @" Image could not be saved: file write failed." , nil );
958
+ success = NO ;
959
+ } else {
960
+ response[@" uri" ] = pathRes;
961
+ }
962
+
954
963
}
955
- response[@" width" ] = @(takenImage.size .width );
956
- response[@" height" ] = @(takenImage.size .height );
964
+
965
+ if (success) {
966
+ response[@" width" ] = @(takenImage.size .width );
967
+ response[@" height" ] = @(takenImage.size .height );
957
968
958
- if ([options[@" base64" ] boolValue ]) {
959
- response[@" base64" ] = [destData base64EncodedStringWithOptions: 0 ];
960
- }
969
+ if ([options[@" base64" ] boolValue ]) {
970
+ response[@" base64" ] = [destData base64EncodedStringWithOptions: 0 ];
971
+ }
961
972
962
- if ([options[@" exif" ] boolValue ]) {
963
- response[@" exif" ] = metadata;
973
+ if ([options[@" exif" ] boolValue ]) {
974
+ response[@" exif" ] = metadata;
964
975
965
- // No longer needed since we always get the photo metadata now
966
- // [RNImageUtils updatePhotoMetadata:imageSampleBuffer withAdditionalData:@{ @"Orientation": @(imageRotation) } inResponse:response]; // TODO
967
- }
976
+ // No longer needed since we always get the photo metadata now
977
+ // [RNImageUtils updatePhotoMetadata:imageSampleBuffer withAdditionalData:@{ @"Orientation": @(imageRotation) } inResponse:response]; // TODO
978
+ }
968
979
969
- response[@" pictureOrientation" ] = @([self .orientation integerValue ]);
970
- response[@" deviceOrientation" ] = @([self .deviceOrientation integerValue ]);
980
+ response[@" pictureOrientation" ] = @([self .orientation integerValue ]);
981
+ response[@" deviceOrientation" ] = @([self .deviceOrientation integerValue ]);
982
+
983
+ if (useFastMode) {
984
+ [self onPictureSaved: @{@" data" : response, @" id" : options[@" id" ]}];
985
+ } else {
986
+ resolve (response);
987
+ }
988
+ }
989
+
971
990
self.orientation = nil ;
972
991
self.deviceOrientation = nil ;
973
-
974
- if (useFastMode) {
975
- [self onPictureSaved: @{@" data" : response, @" id" : options[@" id" ]}];
976
- } else {
977
- resolve (response);
978
- }
979
992
}
980
993
else {
981
994
reject (@" E_IMAGE_CAPTURE_FAILED" , @" Image could not be saved" , error);
0 commit comments