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;
}