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 all 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
])
}
}