Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(camera): Handle 'Limited' iOS Photo permission. #600

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/camera/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utils, ImageSource, ImageAsset, Trace, Frame } from '@nativescript/core';
import { Frame, ImageAsset, ImageSource, Trace, Utils } from '@nativescript/core';
import { CameraOptions } from '.';

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

let authStatus = PHPhotoLibrary.authorizationStatus();
if (authStatus !== PHAuthorizationStatus.Authorized) {
if (authStatus !== PHAuthorizationStatus.Authorized && authStatus !== PHAuthorizationStatus.Limited) {
boutier marked this conversation as resolved.
Show resolved Hide resolved
saveToGallery = false;
}

Expand Down Expand Up @@ -196,9 +196,9 @@ export let isAvailable = function () {

export let requestPermissions = function () {
return new Promise(function (resolve, reject) {
requestPhotosPermissions().then(() => {
requestCameraPermissions().then(resolve, reject);
}, reject);
// Even if we don't have photo access we may want to get camera access.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with ignoring the failure to get photo permissions, if the user does not want photo permissions ( because they are not saving to the gallery) they do not have to call this method, ignoring the failure removes the ability to inform the user, possibly directing them to enable permissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. But:

  • I don't like to have a result that relies on the internal implementation (requesting first photos or first permissions)
  • I don't like to have a failure without knowing which permission was faulty

So, do we want to have something like @nativescript-community/perms that would return a Promise<MultiResult>.

Or something simpler returning just a boolean (granted or not)

requestCameraPermissions(): Promise<0 | 1>
requestPhotosPermissions(): Promise<0 | 2>
requestPermissions(): Promise<number>
enum TypeFlags {
    Camera = 1,
    Photo = 2,
}

const requestCamera = () => requestCameraPermissions().then(resolve, reject);
requestPhotosPermissions().then(requestCamera, requestCamera);
});
};

Expand Down Expand Up @@ -229,6 +229,7 @@ export let requestPhotosPermissions = function () {
}
break;
}
case PHAuthorizationStatus.Limited:
case PHAuthorizationStatus.Authorized: {
if (Trace.isEnabled()) {
Trace.write('Application can access photo library assets.', Trace.categories.Debug);
Expand All @@ -244,6 +245,9 @@ export let requestPhotosPermissions = function () {
reject();
break;
}
default:
((_: never) => {})(authStatus);
break;
}
});
};
Expand Down Expand Up @@ -274,6 +278,9 @@ export let requestCameraPermissions = function () {
reject();
break;
}
default:
((_: never) => {})(cameraStatus);
break;
}
});
};