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.
54 lines
1.5 KiB
54 lines
1.5 KiB
1 year ago
|
//
|
||
|
// SGPermissionPhoto.m
|
||
|
// SGQRCodeExample
|
||
|
//
|
||
|
// Created by kingsic on 2022/7/8.
|
||
|
// Copyright © 2022 kingsic. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "SGPermissionPhoto.h"
|
||
|
#import <Photos/Photos.h>
|
||
|
|
||
|
@implementation SGPermissionPhoto
|
||
|
|
||
|
+ (void)photo:(SGPermissionPhotoBlock)block {
|
||
|
SGPermissionPhoto *photo = [[SGPermissionPhoto alloc] init];
|
||
|
|
||
|
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
|
||
|
if (status == PHAuthorizationStatusNotDetermined) {
|
||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||
|
if (block) {
|
||
|
block(photo, SGPermissionStatusNotDetermined);
|
||
|
}
|
||
|
});
|
||
|
} else if (status == PHAuthorizationStatusAuthorized) {
|
||
|
if (block) {
|
||
|
block(photo, SGPermissionStatusAuthorized);
|
||
|
}
|
||
|
} else if (status == PHAuthorizationStatusDenied) {
|
||
|
if (block) {
|
||
|
block(photo, SGPermissionStatusDenied);
|
||
|
}
|
||
|
} else if (status == PHAuthorizationStatusRestricted) {
|
||
|
if (block) {
|
||
|
block(photo, SGPermissionStatusRestricted);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+ (void)request:(void (^)(BOOL granted))handler {
|
||
|
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
|
||
|
if (status == PHAuthorizationStatusAuthorized) {
|
||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||
|
handler(YES);
|
||
|
});
|
||
|
} else {
|
||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||
|
handler(NO);
|
||
|
});
|
||
|
}
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
@end
|