//
|
// SGPermissionCamera.m
|
// SGQRCodeExample
|
//
|
// Created by kingsic on 2022/7/8.
|
// Copyright © 2022 kingsic. All rights reserved.
|
//
|
|
#import "SGPermissionCamera.h"
|
#import <AVFoundation/AVFoundation.h>
|
|
@implementation SGPermissionCamera
|
|
+ (void)camera:(SGPermissionCameraBlock)block {
|
SGPermissionCamera *camera = [[SGPermissionCamera alloc] init];
|
|
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
if (status == AVAuthorizationStatusNotDetermined) {
|
if (block) {
|
block(camera, SGPermissionStatusNotDetermined);
|
}
|
} else if (status == AVAuthorizationStatusAuthorized) {
|
if (block) {
|
block(camera, SGPermissionStatusAuthorized);
|
}
|
} else if (status == AVAuthorizationStatusDenied) {
|
if (block) {
|
block(camera, SGPermissionStatusDenied);
|
}
|
} else if (status == AVAuthorizationStatusRestricted) {
|
if (block) {
|
block(camera, SGPermissionStatusRestricted);
|
}
|
}
|
}
|
|
+ (void)request:(void (^)(BOOL granted))handler {
|
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
if (granted) {
|
dispatch_async(dispatch_get_main_queue(), ^{
|
handler(YES);
|
});
|
} else {
|
dispatch_async(dispatch_get_main_queue(), ^{
|
handler(NO);
|
});
|
}
|
}];
|
}
|
|
@end
|