Я использую этот код, но, к сожалению, он не работает.
После того, как пользователь отказал в доступе камеры, я хочу попросить у них разрешение на повторное использование камеры в следующий раз, когда они попытаются загрузить его (в этом случае это сканер штрих-кода, использующий вид камеры). Я всегда получаю AVAuthorizationStatusDenied
, а затем granted
всегда автоматически возвращает NO
, хотя я прошу его снова в коде.
Многие из моих пользователей отправляют мне по электронной почте сообщение "мой экран черный, когда я пытаюсь выполнить сканирование штрих-кода", и это потому, что по какой-то причине они отказались от доступа к камере. Я хочу, чтобы иметь возможность запросить их снова, потому что, скорее всего, отказ был ошибкой.
Есть ли способ сделать это?
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
NSLog(@"%@", @"You have camera access");
}
else if(authStatus == AVAuthorizationStatusDenied)
{
NSLog(@"%@", @"Denied camera access");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access to %@", AVMediaTypeVideo);
} else {
NSLog(@"Not granted access to %@", AVMediaTypeVideo);
}
}];
}
else if(authStatus == AVAuthorizationStatusRestricted)
{
NSLog(@"%@", @"Restricted, normally won't happen");
}
else if(authStatus == AVAuthorizationStatusNotDetermined)
{
NSLog(@"%@", @"Camera access not determined. Ask for permission.");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access to %@", AVMediaTypeVideo);
} else {
NSLog(@"Not granted access to %@", AVMediaTypeVideo);
}
}];
}
else
{
NSLog(@"%@", @"Camera access unknown error.");
}