Skip to content

Allow separate request for Camera and Photos permissions #177

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

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ npm install nativescript-camera --save
| Method | Description |
| --- | --- |
| takePicture(options?: CameraOptions) | Take a photo using the camera with an optional parameter for setting different camera options. |
| requestPermissions() | Check required permissions for using device camera. Returns a Promise. |
| requestPermissions() | Request permission from the user for access to their saved photos as well as access to their camera. Returns a Promise. |
| requestCameraPermissions() | Request permission from the user for access to their camera. Returns a Promise. |
| requestPhotosPermissions() | Request permission from the user for access to their saved photos. Returns a Promise. |
| isAvailable() | Is the device camera available to use. |

### CameraOptions
Expand Down
12 changes: 12 additions & 0 deletions src/camera.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ export let requestPermissions = function () {
]);
};

export let requestPhotosPermissions = function () {
return permissions.requestPermissions([
(<any>android).Manifest.permission.WRITE_EXTERNAL_STORAGE,
]);
};

export let requestCameraPermissions = function () {
return permissions.requestPermissions([
(<any>android).Manifest.permission.CAMERA
]);
};

let createDateTimeStamp = function () {
let result = "";
let date = new Date();
Expand Down
4 changes: 2 additions & 2 deletions src/camera.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export let requestPermissions = function () {
});
};

let requestPhotosPermissions = function () {
export let requestPhotosPermissions = function () {
return new Promise(function (resolve, reject) {
let authStatus = PHPhotoLibrary.authorizationStatus();
switch (authStatus) {
Expand Down Expand Up @@ -236,7 +236,7 @@ let requestPhotosPermissions = function () {
});
};

let requestCameraPermissions = function () {
export let requestCameraPermissions = function () {
return new Promise(function (resolve, reject) {
let cameraStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo);
switch (cameraStatus) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function takePicture(options?: CameraOptions): Promise<imageAsset.ImageAs
* Check required permissions for using device camera.
*/
export function requestPermissions(): Promise<any>;
export function requestCameraPermissions(): Promise<any>;
export function requestPhotosPermissions(): Promise<any>;

/**
* Is the camera available to use
Expand Down