1.判斷相冊(cè)權(quán)限
導(dǎo)入<Photos/Photos.h>
+(BOOL)judgeIsHavePhotoAlbumAuthority {
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
return NO;
}
return YES;
}];
}
請(qǐng)求打開相冊(cè)
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
//授權(quán)成功
} else {
//授權(quán)失敗
}];
2.判斷相機(jī)權(quán)限
導(dǎo)入<AVFoundation/AVFoundation.h>
+ (BOOL)judgeIsHaveCameraAuthority {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusDenied || status ==AVAuthorizationStatusRestricted) {
return NO;
}
return YES;
}
請(qǐng)求使用相機(jī)
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
//授權(quán)成功
} else {
//授權(quán)失敗
}
}];
3.判斷麥克風(fēng)權(quán)限
導(dǎo)入<AVFoundation/AVFoundation.h>
+ (BOOL)judgeIsHaveRecordAuthority {
AVAudioSessionRecordPermission status = [[AVAudioSession sharedInstance] recordPermission];
if (status == AVAudioSessionRecordPermissionDenied) {
return NO;
}
return YES;
}
請(qǐng)求使用麥克風(fēng)
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if (granted) {
//授權(quán)成功
} else {
//授權(quán)失敗
}
}];
4.判斷通訊錄權(quán)限
導(dǎo)入<AddressBook/AddressBook.h>
+ (BOOL)judgeIsAddressBookAuthority {
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
return NO;
}
return YES;
}
5.判斷定位權(quán)限
導(dǎo)入<CoreLocation/CoreLocation.h>
+ (BOOL)judgeIsHaveLocationAuthority {
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
BOOL enabled = [CLLocationManager locationServicesEnabled];
if (!enabled || status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted ) {
return NO;
}
return YES;
}
6.判斷日歷權(quán)限
導(dǎo)入<EventKit/EventKit.h>
+ (BOOL)judgeIsHaveCalendarAuthority {
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
if (status == EKAuthorizationStatusDenied || status == EKAuthorizationStatusRestricted) {
return NO;
}
return YES;
}
請(qǐng)求打卡日歷
EKEventStore *eventStore = [[EKEventStore alloc] init];
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
//授權(quán)成功
} else {
//授權(quán)失敗
}
}];
7.判斷藍(lán)牙權(quán)限
+(BOOL)judgeIsHaveBluetoothAuthority {
CBPeripheralManagerAuthorizationStatus status = [CBPeripheralManager authorizationStatus];
if (status == CBPeripheralManagerAuthorizationStatusDenied || status == CBPeripheralManagerAuthorizationStatusRestricted) {
return NO;
}
return YES;
}
注意在Plist文件中添加對(duì)應(yīng)的權(quán)限說明