我想知道如何在按下按钮时屏幕上显示“此应用程序想要访问您的照片/相机:不允许,允许”。我有代码来检查是否启用了照片或相机,但没有启动允许或不允许的操作。我如何为每个(照片和相机)执行此操作?
答案 0 :(得分:1)
在Obj C中
-(void)showImagePicker
{
if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)]) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
// Here you can implement your functions.
} else {
// This condition executes when the user taps Don't Allow option on the alertVeiw. This alert is an one time alert. so you may need to reset the privacy and location settings in your device settings.
[self cancel];
}
});
}];
} else {
[self cancel];
}
}
答案 1 :(得分:0)
点击提到的按钮时执行以下操作:
的OBJ-C:
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus) {
if (authorizationStatus == PHAuthorizationStatusAuthorized) {
// Add your custom logic here
}
}];
夫特:
PHPhotoLibrary.requestAuthorization { (authorizationStatus) -> Void in
if authorizationStatus == .Authorized {
// Add your custom logic here
}
}
如果需要,系统会弹出允许访问照片库的权限。