Skip to content

Commit

Permalink
Request permission to use the camera with the target being the camera
Browse files Browse the repository at this point in the history
  • Loading branch information
tucoi052 committed Nov 1, 2023
1 parent 7ebc765 commit 138d12e
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions ios/ImagePickerManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,50 @@ - (void)checkCameraPermissions:(void(^)(BOOL granted))callback

- (void)checkPhotosPermissions:(void(^)(BOOL granted))callback
{
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusAuthorized) {
callback(YES);
return;
} else if (status == PHAuthorizationStatusNotDetermined) {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
callback(YES);
return;
}
else {
callback(NO);
return;
}
}];
// Request permission to use the camera with the target being the camera
if(target == camera) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusAuthorized) {
callback(YES);
return;
} else if (status == AVAuthorizationStatusAuthorized) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
callback(YES);
return;
}
else {
callback(NO);
return;
}
}];
}
else {
callback(NO);
}
}
else {
callback(NO);
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusAuthorized) {
callback(YES);
return;
} else if (status == PHAuthorizationStatusNotDetermined) {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
callback(YES);
return;
}
else {
callback(NO);
return;
}
}];
}
else {
callback(NO);
}
}

}

// Both camera and photo write permission is required to take picture/video and store it to public photos
Expand Down

0 comments on commit 138d12e

Please sign in to comment.