1.判斷用戶是否有權(quán)限訪問相冊
#import <AssetsLibrary/AssetsLibrary.h>
ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];
if (author == ALAuthorizationStatusRestricted || author ==ALAuthorizationStatusDenied){
//無權(quán)限 做一個(gè)友好的提示
UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"溫馨提示" message:@"請您設(shè)置允許APP訪問您的相冊\n設(shè)置>隱私>照片" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alart show];
return ;
} else {
//打開相機(jī)
}
ALAuthorizationStatus是一個(gè)系統(tǒng)的枚舉。含義如下捌刮。
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
AVAuthorizationStatusNotDetermined = 0,// 用戶尚未做出選擇這個(gè)應(yīng)用程序的問候
AVAuthorizationStatusRestricted,// 此應(yīng)用程序沒有被授權(quán)訪問的照片數(shù)據(jù)【呕穑可能是家長控制權(quán)限
AVAuthorizationStatusDenied,// 用戶已經(jīng)明確否認(rèn)了這一照片數(shù)據(jù)的應(yīng)用程序訪問
AVAuthorizationStatusAuthorized// 用戶已經(jīng)授權(quán)應(yīng)用訪問照片數(shù)據(jù)
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
2.判斷用戶是否有權(quán)限訪問相機(jī)
iOS7之前都可以訪問相機(jī)饺鹃,iOS7之后訪問相機(jī)有權(quán)限設(shè)置
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
{
//無權(quán)限 做一個(gè)友好的提示
UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"溫馨提示" message:@"請您設(shè)置允許APP訪問您的相機(jī)\n設(shè)置>隱私>相機(jī)" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alart show];
return ;
} else {
//調(diào)用相機(jī)
}
3.判斷定位服務(wù)是否可用
if ([CLLocationManager locationServicesEnabled] &&
([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized
|| [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {
//定位功能可用庐舟,開始定位
_locationManger = [[CLLocationManager alloc] init];
locationManger.delegate = self;
[locationManger startUpdatingLocation];
}
else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){
NSlog("定位功能不可用氓皱,提示用戶或忽略");
}