@@ -750,13 +750,24 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
750
750
return ;
751
751
}
752
752
753
- if (!self.deviceOrientation ) {
754
- [self takePictureWithOrientation: options resolve: resolve reject: reject];
755
- return ;
756
- }
757
-
758
- NSInteger orientation = [options[@" orientation" ] integerValue ];
753
+ // make sure to get orientation info here
754
+ // as it may change if multiple consecutive calls are done
755
+ NSInteger orientation;
756
+ NSNumber * deviceOrientation;
757
+
758
+ @synchronized (self) {
759
+ if (!self.deviceOrientation ) {
760
+ [self takePictureWithOrientation: options resolve: resolve reject: reject];
761
+ return ;
762
+ }
759
763
764
+ orientation = [options[@" orientation" ] integerValue ];
765
+ deviceOrientation = self.deviceOrientation ;
766
+
767
+ self.orientation = nil ;
768
+ self.deviceOrientation = nil ;
769
+ }
770
+
760
771
AVCaptureConnection *connection = [self .stillImageOutput connectionWithMediaType: AVMediaTypeVideo];
761
772
[connection setVideoOrientation: orientation];
762
773
@try {
@@ -923,7 +934,7 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
923
934
}
924
935
925
936
}
926
-
937
+
927
938
CFDictionaryRef finalMetaData = nil ;
928
939
if (writeExif) {
929
940
finalMetaData = (__bridge CFDictionaryRef )metadata;
@@ -950,7 +961,7 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
950
961
}
951
962
952
963
bool success = YES ;
953
-
964
+
954
965
if (![options[@" doNotSave" ] boolValue ]) {
955
966
NSString * pathRes = [RNImageUtils writeImage: destData toPath: path];
956
967
if (!pathRes) {
@@ -959,9 +970,9 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
959
970
} else {
960
971
response[@" uri" ] = pathRes;
961
972
}
962
-
973
+
963
974
}
964
-
975
+
965
976
if (success) {
966
977
response[@" width" ] = @(takenImage.size .width );
967
978
response[@" height" ] = @(takenImage.size .height );
@@ -977,18 +988,15 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
977
988
// [RNImageUtils updatePhotoMetadata:imageSampleBuffer withAdditionalData:@{ @"Orientation": @(imageRotation) } inResponse:response]; // TODO
978
989
}
979
990
980
- response[@" pictureOrientation" ] = @([ self . orientation integerValue ] );
981
- response[@" deviceOrientation" ] = @([self . deviceOrientation integerValue ]);
982
-
991
+ response[@" pictureOrientation" ] = @(orientation);
992
+ response[@" deviceOrientation" ] = @([deviceOrientation integerValue ]);
993
+
983
994
if (useFastMode) {
984
995
[self onPictureSaved: @{@" data" : response, @" id" : options[@" id" ]}];
985
996
} else {
986
997
resolve (response);
987
998
}
988
999
}
989
-
990
- self.orientation = nil ;
991
- self.deviceOrientation = nil ;
992
1000
}
993
1001
else {
994
1002
reject (@" E_IMAGE_CAPTURE_FAILED" , @" Image could not be saved" , error);
@@ -1016,7 +1024,7 @@ - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)reso
1016
1024
}
1017
1025
1018
1026
- (void )recordWithOrientation : (NSDictionary *)options resolve : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject {
1019
-
1027
+
1020
1028
UIInterfaceOrientation orientation = [self .sensorOrientationChecker getDeviceOrientation ];
1021
1029
NSMutableDictionary *tmpOptions = [options mutableCopy ];
1022
1030
if ([tmpOptions valueForKey: @" orientation" ] == nil ) {
@@ -1111,7 +1119,6 @@ - (void)record:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve r
1111
1119
// with this and the captureAudio prop
1112
1120
dispatch_async (self.sessionQueue , ^{
1113
1121
[self initializeAudioCaptureSessionInput ];
1114
-
1115
1122
// finally, make sure we got access to the capture device
1116
1123
// and turn the connection on.
1117
1124
if (self.audioCaptureDeviceInput != nil ){
@@ -1186,17 +1193,17 @@ - (void)record:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve r
1186
1193
if (options[@" codec" ]) {
1187
1194
if (@available (iOS 10 , *)) {
1188
1195
AVVideoCodecType videoCodecType = options[@" codec" ];
1189
-
1196
+
1190
1197
if ([self .movieFileOutput.availableVideoCodecTypes containsObject: videoCodecType]) {
1191
1198
self.videoCodecType = videoCodecType;
1192
-
1199
+
1193
1200
BOOL supportsBitRate = NO ;
1194
-
1201
+
1195
1202
// prevent crashing due to unsupported keys
1196
1203
if (@available (iOS 12.0 , *)) {
1197
1204
supportsBitRate = [[self .movieFileOutput supportedOutputSettingsKeysForConnection: connection] containsObject: AVVideoCompressionPropertiesKey];
1198
1205
}
1199
-
1206
+
1200
1207
if (options[@" videoBitrate" ] && supportsBitRate) {
1201
1208
NSString *videoBitrate = options[@" videoBitrate" ];
1202
1209
[self .movieFileOutput setOutputSettings: @{
@@ -2017,7 +2024,7 @@ - (void)mirrorVideo:(NSURL *)inputURL completion:(void (^)(NSURL* outputUR))comp
2017
2024
2018
2025
[instruction setLayerInstructions: @[transformer]];
2019
2026
[videoComposition setInstructions: @[instruction]];
2020
-
2027
+
2021
2028
// get preset for export via default or session
2022
2029
AVCaptureSessionPreset preset = [self getDefaultPreset ];
2023
2030
if (self.session .sessionPreset != preset) {
0 commit comments