Skip to content

Commit

Permalink
feat(Permissions): allow microphone check (#3068)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyDenZ authored Jun 8, 2020
1 parent 179104c commit a2f2e4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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
])
}
}

0 comments on commit a2f2e4f

Please sign in to comment.