Files
iNaturalistReactNative/patches/@react-native-camera-roll+camera-roll+7.5.2.patch
Ken-ichi 899076e67a Only ask for permission to add photos from cameras (#1869)
* Patch camera roll to not ask for readwrite after addonly granted
* Only request add permission from cameras
2024-07-29 11:51:14 -07:00

32 lines
1.5 KiB
Diff

diff --git a/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm
index b8f2aa2..aa0df68 100644
--- a/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm
+++ b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm
@@ -207,6 +207,26 @@ RCT_EXPORT_METHOD(saveToCameraRoll:(NSURLRequest *)request
}
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
+ // If the write succeeded but we don't have readwrite permission, that
+ // means we have addonly permission and we cannot read the file we
+ // just created to construct a response
+ if (@available(iOS 14, *)) {
+ PHAuthorizationStatus readWriteAuthStatus = [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite];
+ if (readWriteAuthStatus != PHAuthorizationStatusAuthorized) {
+ NSDictionary *addOnlyResponse = @{
+ @"node": @{
+ @"id": placeholder.localIdentifier,
+ @"type": options[@"type"],
+ @"image": @{
+ @"uri": @"placeholder/readWritePermissionNotGranted"
+ }
+ }
+ };
+ resolve(addOnlyResponse);
+ return;
+ }
+ }
+
PHFetchOptions *options = [PHFetchOptions new];
options.includeHiddenAssets = YES;
options.includeAllBurstAssets = YES;