相机权限
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == ALAuthorizationStatusRestricted || authStatus == ALAuthorizationStatusDenied){
//无权限
NSString *tips = [NSString stringWithFormat:@"请在iPhone的”设置-隐私-相机“选项中,允许%@访问你的手机相机",NSLocalizedString(@"AppName",@"GMChatDemo")];
[UIAlertView showWithTitle:@" " message:tips cancelButtonTitle:@"好" otherButtonTitles:nil tapBlock:nil];
return;
}
相册权限
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//无权限
NSString *tips = [NSString stringWithFormat:@"请在iPhone的”设置-隐私-照片“选项中,允许%@访问你的照片",NSLocalizedString(@"AppName",@"GMChatDemo")];
[UIAlertView showWithTitle:@" " message:tips cancelButtonTitle:@"好" otherButtonTitles:nil tapBlock:nil];
return;
}
麦克风权限(录音等)
+ (BOOL)canRecord
{
__block BOOL bCanRecord = YES;
if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
[audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
bCanRecord = granted;
}];
}
}
return bCanRecord;
}
定位权限
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
[self showHint:NSLocalizedString(@"location.open","please open location")];
return;
}
网友评论