iPhone系统权限

2016-07-11  本文已影响33人  SincereDu
#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;
}
上一篇下一篇

猜你喜欢

热点阅读