This project is a template to deal with camera permission with ARKit. According to Apple Human Interface Guidelines we have to explain by description in an alert dialog the reason why the application needs permissions. However Apple rejected my application because it did not have a function which requests permission again when it appeared. This function is common at most of applications, so I decided make a template which requests a camera permission.
source codes refer to Swift Cheat Sheet for iPhone Camera Access & Usage.
-
let cameraAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
is getting present authenticate status. We can handle it at ViewDidAppear(). -
checkPermission()
is checking present status and executing operations by each states-
.notDetermined
request a permission by callingrequestCameraPermission()
It shows alert dialog generated by iOS. We have to describe explanation on it, and it is declared at InfoPlist.strings. -
.restricted & .denied ask to set a permission by
alertCameraAccessNeeded()
It shows application original alert dialog. -
.authorized
Do nothing. (We have to implement operations after getting a permission)
-
-
NotificationCenter.default.addObserver(self, selector: #selector(checkPermission), name: UIApplication.willEnterForegroundNotification, object: nil)
is for showing a dialog automatically when the application comes back foreground.
- Prerquisites: You must have a device running iOS 9 and more higher with an A9 or later processor and XCode 10.1. Both of these are currently in beta but are available via the Apple Developer portal.
- Download the source code for this project and open the project in XCode 10.1.
- Change the Bundle Identifier and Team to your own unique identifier and team. Note that this project does not require a developer license to run on a phone, so you can use a personal team.
- Run in XCode on your device.