Quantcast
Viewing latest article 2
Browse Latest Browse All 2

iOS camera authorization - wrong status

I use the following code to check and request authorization for the Camera. Problem is the following. The following scenario leads to a wrong authorization status:

  1. User declines authorization for the first time
  2. Terminates the app
  3. Restarts the app
  4. Leaves the application, grants authorization for the camera in settings app
  5. Returns to the app

[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] will return AVAuthorizationStatusDeclined (authorized as said).

After terminating and restarting results in AVAuthorizationStatusAuthorized as it should. In this case the user leaves to settings and denies camera access the result will remain AVAuthorizationStatusAuthorized until next restart.

Any ideas what I miss here?

- (void) popCamera {    UIImagePickerController *picker = [[UIImagePickerController alloc] init];    picker.delegate = self;    //picker.allowsEditing = YES;    #if !(TARGET_IPHONE_SIMULATOR)    picker.sourceType = UIImagePickerControllerSourceTypeCamera;    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;    #endif    self.view.translatesAutoresizingMaskIntoConstraints = YES;    [self presentViewController:picker animated:YES completion:NULL];}- (void)camDenied{    NSLog(@"%@", @"Denied camera access");    NSString *alertText;    NSString *alertButton;    BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);    if (canOpenSettings)    {        alertText = LSS(@"DeniedCamera1");        SDCAlertView *alert = [[SDCAlertView alloc]                              initWithTitle:LSS(@"DeniedCameraTitle")                              message:alertText                              delegate:self                              cancelButtonTitle:LSS(@"Cancel")                              otherButtonTitles:LSS(@"Goto"), nil];        alert.tag = 3491832;        [alert show];    }    else    {        alertText = LSS(@"DeniedCamera2");        SDCAlertView *alert = [[SDCAlertView alloc]                              initWithTitle:LSS(@"DeniedCameraTitle")                              message:alertText                              delegate:self                              cancelButtonTitle:LSS(@"Cancel")                              otherButtonTitles:nil];        alert.tag = 3491832;        [alert show];    }}- (IBAction) onTakePhoto:(id)sender {    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];    if(authStatus == AVAuthorizationStatusAuthorized)    {        [self popCamera];    }    else if(authStatus == AVAuthorizationStatusNotDetermined)    {        NSLog(@"%@", @"Camera access not determined. Ask for permission.");        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)         {             if(granted)             {                 [self popCamera];             }             else             {                 [self camDenied];             }         }];    }    else if (authStatus == AVAuthorizationStatusRestricted)    {        SDCAlertView *alert = [[SDCAlertView alloc]                              initWithTitle:LSS(@"RestrictCameraTitle")                              message:LSS(@"RestrictCamera")                              delegate:self                              cancelButtonTitle:LSS(@"OK")                              otherButtonTitles:nil];    }    else    {        [self camDenied];    }    }

Credits for the original code: Is there a way to ask user for Camera access after they have already denied it on iOS 8?


Viewing latest article 2
Browse Latest Browse All 2

Trending Articles