林晖杰 林晖杰 - 4 months ago 12
iOS Question

How to know user clicked "Not Allow" button when iOS ask user to grant permission to access camera or Library?

On iOS8+, user first time to access the Camera or Library. in this moment system will show a alertView to let user to grant the permission, so i want to know is there have any way to know user have click "Not allow"?

Appreciate your help.

Answer

This might helps you for your issue.!

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.
        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.
        }
    }];
} else {
    // We are on iOS <= 6. Just do what we need to do.
    [self doStuff];
}