导入头文件
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
参考代码
// 拍照
if (buttonIndex == kSourceTypeCamera) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
NSLog(@"您没权限访问相机");
}
else {
// 显示界面
[self showImagePickerWithSourceType:UIImagePickerControllerSourceTypeCamera];
}
}
// 相册
else if (buttonIndex == kSourceTypePhotoLibrary) {
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied){
NSLog@"您没权限访问相册");
}
else {
// 显示界面
[self showImagePickerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
}
网友评论