You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

51 lines
1.5 KiB

//
// 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