美文网首页
iPhone系统权限

iPhone系统权限

作者: SincereDu | 来源:发表于2016-07-11 10:06 被阅读33次
    • 需要引用到的头文件有
    #import <AssetsLibrary/AssetsLibrary.h>
    #import <AVFoundation/AVFoundation.h>
    #import <AddressBook/AddressBook.h>
    #import <CoreLocation/CoreLocation.h>
    #import <UIKit/UIKit.h>
    
    • 相册权限
    + (BOOL) isPhotosAuthorized;
    {
        ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
        if (author == ALAuthorizationStatusDenied)
        {
            return NO;
        }
        return YES;
    }
    
    • 照相机权限
    + (BOOL) isCameraAuthorized
    {
        AVAuthorizationStatus avStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        BOOL isHaveCamera = (avStatus == AVAuthorizationStatusAuthorized || avStatus == AVAuthorizationStatusNotDetermined);
        if (!isHaveCamera)
        {
            return NO;
        }
        return YES;
    }
    
    • 麦克风权限
    + (BOOL) isMicroPhoneAuthorized
    {
            __block BOOL bCanRecord = YES;
            AVAudioSession *audioSession = [AVAudioSession sharedInstance];
            if ([audioSession respondsToSelector:@selector(requestRecordPermission:)])
            {
                [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
                bCanRecord = granted;
                }];
            }
            return bCanRecord;
    }
    
    • 通知权限
    + (BOOL) isNotificationAuthorized
    {
            BOOL isAllowNotifi = NO;
            UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
            if (UIUserNotificationTypeNone != setting.types)
            {
                isAllowNotifi = YES;
            }
            return isAllowNotifi;
    }
    
    • 定位权限
    + (BOOL)isLocatonAuthorized
    {
            if (![CLLocationManager locationServicesEnabled])
            {
                return NO;
            }
        
            CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
            if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways )
            {
                return YES;
            }
            return NO;
    }
    
    • 通讯录权限
    + (BOOL) isContactsAuthorized
    {
            if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusDenied || ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusRestricted)
            {
                return NO;
            }
            return YES;
    }
    

    相关文章

      网友评论

          本文标题:iPhone系统权限

          本文链接:https://www.haomeiwen.com/subject/ejtjjttx.html