У меня есть приложение с сканером QR-кода, которое отлично работает, но на iOS 8 по умолчанию доступ к камере «Отказано». Поэтому я должен войти в настройки и вручную предоставить доступ к приложению для использования камеры. Как я могу сделать подсказку, которая говорит что-то вроде «Хотите ли вы предоставить этому приложению доступ к использованию камеры»?iOS: запрос на доступ к камере
Вот пример моего кода, проверяющего разрешения камеры, а затем запрашивающего разрешения, если пользователь не дал их. Тем не менее, ссылка для предоставления разрешений никогда не появляется и в итоге просто показывает UIAlertView. Состояние действительно ДЕСЯТЬ, когда я тестирую, так есть причина, по которой он не просит разрешения? Благодаря!
Также у меня есть #import AVFoundation/AVFoundation.h, так что это не проблема.
-(void) checkCameraAuthorization {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(status == AVAuthorizationStatusAuthorized) { // authorized
NSLog(@"camera authorized");
}
else if(status == AVAuthorizationStatusDenied){ // denied
if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)]) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
// Will get here on both iOS 7 & 8 even though camera permissions weren't required
// until iOS 8. So for iOS 7 permission will always be granted.
NSLog(@"DENIED");
if (granted) {
// Permission has been granted. Use dispatch_async for any UI updating
// code because this block may be executed in a thread.
dispatch_async(dispatch_get_main_queue(), ^{
//[self doStuff];
});
} else {
// Permission has been denied.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Authorized" message:@"Please go to Settings and enable the camera for this app to use this feature." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}];
}
}
else if(status == AVAuthorizationStatusRestricted){ // restricted
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Authorized" message:@"Please go to Settings and enable the camera for this app to use this feature." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else if(status == AVAuthorizationStatusNotDetermined){ // not determined
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){ // Access has been granted ..do something
NSLog(@"camera authorized");
} else { // Access denied ..do something
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Authorized" message:@"Please go to Settings and enable the camera for this app to use this feature." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}];
}
}
Ответил здесь: http://stackoverflow.com/questions/24229422/accessing-the-settings-app-from-your -app-in-ios-8 –