AVCapture.mm
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "AVCapture.h"
#include <AVFoundation/AVFoundation.h>
static NSString* MediaTypeFromEnum(int captureType)
{
if (captureType == avAudioCapture)
return AVMediaTypeAudio;
else if (captureType == avVideoCapture)
return AVMediaTypeVideo;
return nil;
}
extern "C" int UnityGetAVCapturePermission(int captureType)
{
NSString* mediaType = MediaTypeFromEnum(captureType);
if (mediaType == nil)
return avCapturePermissionDenied;
#if !PLATFORM_TVOS && (UNITY_USES_WEBCAM || UNITY_USES_MICROPHONE)
NSInteger status = AVAuthorizationStatusAuthorized;
status = [AVCaptureDevice authorizationStatusForMediaType: mediaType];
if (status == AVAuthorizationStatusNotDetermined)
return avCapturePermissionUnknown;
else if (status == AVAuthorizationStatusAuthorized)
return avCapturePermissionGranted;
#endif
return avCapturePermissionDenied;
}
extern "C" void UnityRequestAVCapturePermission(int captureType)
{
#if !PLATFORM_TVOS && (UNITY_USES_WEBCAM || UNITY_USES_MICROPHONE)
NSString* mediaType = MediaTypeFromEnum(captureType);
if (mediaType == nil)
return;
[AVCaptureDevice requestAccessForMediaType: mediaType completionHandler:^(BOOL granted) {
UnityReportAVCapturePermission();
}];
#endif
}