Project

General

Profile

BitmapToolkit Scol plugin
CameraPermissionIOS.mm
Go to the documentation of this file.
1//
2// CameraPermissionIOS.m
3// Scol
4//
5// Created by Bastien on 16/06/2016.
6//
7//
8
10#import <AVFoundation/AVFoundation.h>
11
12
14{
15 if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)])
16 {
17 [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
18 {
19 // Will get here on both iOS 7 & 8 even though camera permissions weren't required
20 // until iOS 8. So for iOS 7 permission will always be granted.
21 if (granted)
22 {
23 // Permission has been granted. Use dispatch_async for any UI updating
24 // code because this block may be executed in a thread.
25 dispatch_sync(dispatch_get_main_queue(), ^{
26 NSLog(@">> Camera permission granted");
27 });
28 }
29 else
30 {
31 NSLog(@">> Camera permission denied");
32 }
33 }];
34 }
35 else
36 {
37 NSLog(@">> Camera permission granted");
38 }
39}
40
42{
43 AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
44 if(authStatus == AVAuthorizationStatusAuthorized)
45 {
46 NSLog(@"Already granted access to %@", AVMediaTypeVideo);
47 }
48 else if(authStatus == AVAuthorizationStatusDenied)
49 {
50 NSLog(@"Already denied access to %@", AVMediaTypeVideo);
51 } else if(authStatus == AVAuthorizationStatusRestricted){
52 NSLog(@"Already denied access to %@", AVMediaTypeVideo);
53 } else if(authStatus == AVAuthorizationStatusNotDetermined){
54 // not determined?!
55 [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
56 if(granted){
57 NSLog(@"Granted access to %@", AVMediaTypeVideo);
58 } else {
59 NSLog(@"Not granted access to %@", AVMediaTypeVideo);
60 }
61 }];
62 } else {
63 // impossible, unknown authorization status
64 }
65}
void CheckCameraPermissionBis()
Prompts the user with a camera permission dialog if this is the first time the app is run....
void CheckCameraPermission()
Prompts the user with a camera permission dialog if this is the first time the app is run.