Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Permissions): allow microphone check #3068

Merged
merged 4 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public void query(PluginCall call) {
case "clipboard-read":
case "clipboard-write":
checkClipboard(call);
case "microphone":
checkMicrophone(call);
break;
default:
call.reject("Unknown permission type");
Expand Down Expand Up @@ -80,4 +82,8 @@ private void checkClipboard(PluginCall call) {
call.resolve(ret);
}

private void checkMicrophone(PluginCall call) {
checkPerm(Manifest.permission.RECORD_AUDIO, call);
}

}
3 changes: 2 additions & 1 deletion core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,8 @@ export enum PermissionType {
Geolocation = 'geolocation',
Notifications = 'notifications',
ClipboardRead = 'clipboard-read',
ClipboardWrite = 'clipboard-write'
ClipboardWrite = 'clipboard-write',
Microphone = 'microphone'
}

export interface PermissionsOptions {
Expand Down
20 changes: 20 additions & 0 deletions ios/Capacitor/Capacitor/Plugins/Permissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class CAPPermissionsPlugin: CAPPlugin {
return checkClipboard(call)
case "photos":
return checkPhotos(call)
case "microphone":
return checkMicrophone(call)
default:
return call.reject("Unknown permission type")
}
Expand Down Expand Up @@ -108,4 +110,22 @@ public class CAPPermissionsPlugin: CAPPlugin {
"state": "granted"
])
}

func checkMicrophone(_ call: CAPPluginCall) {
let microStatus = AVCaptureDevice.authorizationStatus(for: .audio)

var ret = "prompt"
switch (microStatus) {
case .authorized:
ret = "granted"
case .denied, .restricted:
ret = "denied"
case .notDetermined:
ret = "prompt"
}

call.resolve([
"state": ret
])
}
}
7 changes: 7 additions & 0 deletions site/src/assets/docs-content/apis/permissions/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,12 @@ <h4 class="avc-code-interface-name">PermissionType</h4>
<avc-code-type">"photos"</avc-code-type>
</div>
</div>

<div class="avc-code-interface-param">
<div class="avc-code-param-comment"></div>
<div class="avc-code-line"><span class="avc-code-param-name">Microphone</span>:
<avc-code-type">"microphone"</avc-code-type>
</div>
</div>
<span class="avc-code-line"><span class="avc-code-brace">}</span></span>
</div>