Skip to content

Commit ead4beb

Browse files
authored
fix(camera): Handle 'Limited' iOS Photo permission. (#600)
Limited means "we have access to some photos and you can save photos from the application". Thus, when we give a limited access to the gallery: - succeed - save to gallery In this patch, also add code to check that the switch is exhaustive, such that compilation will fail and we won't forget to handle future cases.
1 parent 90478ec commit ead4beb

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/camera/index.ios.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Utils, ImageSource, ImageAsset, Trace, Frame } from '@nativescript/core';
1+
import { Frame, ImageAsset, ImageSource, Trace, Utils } from '@nativescript/core';
22
import { CameraOptions } from '.';
33

44
@NativeClass()
@@ -78,7 +78,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
7878
} else {
7979
Trace.write('An error ocurred while saving image to gallery: ' + err, Trace.categories.Error, Trace.messageType.error);
8080
}
81-
}
81+
},
8282
);
8383
} else {
8484
imageAsset = new ImageAsset(imageSourceResult.ios);
@@ -143,7 +143,7 @@ export let takePicture = function (options: CameraOptions): Promise<any> {
143143
}
144144

145145
let authStatus = PHPhotoLibrary.authorizationStatus();
146-
if (authStatus !== PHAuthorizationStatus.Authorized) {
146+
if (authStatus !== PHAuthorizationStatus.Authorized && authStatus !== PHAuthorizationStatus.Limited) {
147147
saveToGallery = false;
148148
}
149149

@@ -196,9 +196,9 @@ export let isAvailable = function () {
196196

197197
export let requestPermissions = function () {
198198
return new Promise(function (resolve, reject) {
199-
requestPhotosPermissions().then(() => {
200-
requestCameraPermissions().then(resolve, reject);
201-
}, reject);
199+
// Even if we don't have photo access we may want to get camera access.
200+
const requestCamera = () => requestCameraPermissions().then(resolve, reject);
201+
requestPhotosPermissions().then(requestCamera, requestCamera);
202202
});
203203
};
204204

@@ -229,6 +229,7 @@ export let requestPhotosPermissions = function () {
229229
}
230230
break;
231231
}
232+
case PHAuthorizationStatus.Limited:
232233
case PHAuthorizationStatus.Authorized: {
233234
if (Trace.isEnabled()) {
234235
Trace.write('Application can access photo library assets.', Trace.categories.Debug);
@@ -244,6 +245,9 @@ export let requestPhotosPermissions = function () {
244245
reject();
245246
break;
246247
}
248+
default:
249+
((_: never) => {})(authStatus);
250+
break;
247251
}
248252
});
249253
};
@@ -274,6 +278,9 @@ export let requestCameraPermissions = function () {
274278
reject();
275279
break;
276280
}
281+
default:
282+
((_: never) => {})(cameraStatus);
283+
break;
277284
}
278285
});
279286
};

0 commit comments

Comments
 (0)