mirror of
https://github.com/defold/extension-camera
synced 2025-09-27 17:02:19 +02:00
Only check permission on newer iOS and macOS versions
This commit is contained in:
@@ -392,42 +392,50 @@ void CameraPlatform_StartCaptureAuthorized(dmBuffer::HBuffer* buffer, CameraType
|
||||
|
||||
void CameraPlatform_StartCapture(dmBuffer::HBuffer* buffer, CameraType type, CaptureQuality quality, CameraInfo& outparams)
|
||||
{
|
||||
// Request permission to access the camera.
|
||||
int status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
if (status == AVAuthorizationStatusAuthorized)
|
||||
// Only check for permission on iOS 7+ and macOS 10.14+
|
||||
if ([AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)])
|
||||
{
|
||||
// Request permission to access the camera.
|
||||
int status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
if (status == AVAuthorizationStatusAuthorized)
|
||||
{
|
||||
// The user has previously granted access to the camera.
|
||||
dmLogInfo("AVAuthorizationStatusAuthorized");
|
||||
CameraPlatform_StartCaptureAuthorized(buffer, type, quality, outparams);
|
||||
}
|
||||
else if (status == AVAuthorizationStatusNotDetermined)
|
||||
{
|
||||
dmLogInfo("AVAuthorizationStatusNotDetermined");
|
||||
// The app hasn't yet asked the user for camera access.
|
||||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
||||
if (granted) {
|
||||
dmLogInfo("AVAuthorizationStatusNotDetermined - granted!");
|
||||
CameraPlatform_StartCaptureAuthorized(buffer, type, quality, outparams);
|
||||
}
|
||||
else
|
||||
{
|
||||
dmLogInfo("AVAuthorizationStatusNotDetermined - not granted!");
|
||||
Camera_QueueMessage(STATUS_NOT_PERMITTED);
|
||||
}
|
||||
}];
|
||||
}
|
||||
else if (status == AVAuthorizationStatusDenied)
|
||||
{
|
||||
// The user has previously denied access.
|
||||
dmLogInfo("AVAuthorizationStatusDenied");
|
||||
Camera_QueueMessage(STATUS_NOT_PERMITTED);
|
||||
}
|
||||
else if (status == AVAuthorizationStatusRestricted)
|
||||
{
|
||||
// The user can't grant access due to restrictions.
|
||||
dmLogInfo("AVAuthorizationStatusRestricted");
|
||||
Camera_QueueMessage(STATUS_NOT_PERMITTED);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The user has previously granted access to the camera.
|
||||
dmLogInfo("AVAuthorizationStatusAuthorized");
|
||||
CameraPlatform_StartCaptureAuthorized(buffer, type, quality, outparams);
|
||||
}
|
||||
else if (status == AVAuthorizationStatusNotDetermined)
|
||||
{
|
||||
dmLogInfo("AVAuthorizationStatusNotDetermined");
|
||||
// The app hasn't yet asked the user for camera access.
|
||||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
||||
if (granted) {
|
||||
dmLogInfo("AVAuthorizationStatusNotDetermined - granted!");
|
||||
CameraPlatform_StartCaptureAuthorized(buffer, type, quality, outparams);
|
||||
}
|
||||
else
|
||||
{
|
||||
dmLogInfo("AVAuthorizationStatusNotDetermined - not granted!");
|
||||
Camera_QueueMessage(STATUS_NOT_PERMITTED);
|
||||
}
|
||||
}];
|
||||
}
|
||||
else if (status == AVAuthorizationStatusDenied)
|
||||
{
|
||||
// The user has previously denied access.
|
||||
dmLogInfo("AVAuthorizationStatusDenied");
|
||||
Camera_QueueMessage(STATUS_NOT_PERMITTED);
|
||||
}
|
||||
else if (status == AVAuthorizationStatusRestricted)
|
||||
{
|
||||
// The user can't grant access due to restrictions.
|
||||
dmLogInfo("AVAuthorizationStatusRestricted");
|
||||
Camera_QueueMessage(STATUS_NOT_PERMITTED);
|
||||
}
|
||||
}
|
||||
|
||||
void CameraPlatform_StopCapture()
|
||||
|
Reference in New Issue
Block a user