整理下iOS开发中 应用申请常用权限
#import typedef void (^AuthorizedFinishBlock)();
@interface LYAuthorizedMaster : NSObject
#pragma mark - 摄像头权限
+(BOOL)checkCameraAuthority;
+(void)cameraAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
#pragma mark - 麦克风权限
+(BOOL)checkAudioAuthority;
+(void)audioAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
#pragma mark - 相册权限
+(BOOL)checkAlbumAuthority;
+(void)albumAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
#pragma mark - 推送通知权限
+(BOOL)checkPushNotificationAuthority;
+(void)pushNotificationAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
#pragma mark - 推送通知权限
+(BOOL)checkLocationAuthority;
+(void)locationAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
#pragma mark - 通讯录权限
+(BOOL)checkAddressBookAuthority;
+(void)AddressBookAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
下面是.m文件
里面引入了很多库文件,也不是所用项目都会用到的,用不到的注掉就好。
#import "LYAuthorizedMaster.h"
#import //摄像头麦克风 必须
#import //相册权限
#import //位置权限
#import //通讯录权限
#import "AppDelegate.h"
#define kAPPName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
@implementation LYAuthorizedMaster
#pragma mark -
+(BOOL)checkAuthority:(AVAuthorizationStatus)_status{
return (_status == AVAuthorizationStatusAuthorized) || (_status == AVAuthorizationStatusNotDetermined);
}
+(void)showAlertController:(AuthorizedFinishBlock)_block device:(NSString *)_device{
UIAlertController *_alertC = [UIAlertController alertControllerWithTitle:@"没有权限" message:[NSString stringWithFormat:@"请开启‘%@’对 %@ 的使用权限",kAPPName,_device] preferredStyle:UIAlertControllerStyleAlert];
[_alertC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];