From 77d89b86117a9e1adc88abfafc8c9327ea5fef8d Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 7 Jun 2024 16:00:38 +0200 Subject: [PATCH] feat!: Remove deprecated permission methods (#94) --- README.md | 26 -------- .../speechrecognition/SpeechRecognition.java | 17 ------ ios/Plugin/Plugin.swift | 60 ------------------- src/definitions.ts | 17 ------ 4 files changed, 120 deletions(-) diff --git a/README.md b/README.md index 892bc36..89f5b1c 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,7 @@ No further action required. * [`start(...)`](#start) * [`stop()`](#stop) * [`getSupportedLanguages()`](#getsupportedlanguages) -* [`hasPermission()`](#haspermission) * [`isListening()`](#islistening) -* [`requestPermission()`](#requestpermission) * [`checkPermissions()`](#checkpermissions) * [`requestPermissions()`](#requestpermissions) * [`addListener('partialResults', ...)`](#addlistenerpartialresults-) @@ -160,19 +158,6 @@ It's not available on Android 13 and newer. -------------------- -### hasPermission() - -```typescript -hasPermission() => Promise<{ permission: boolean; }> -``` - -This method will check for audio permissions. - -**Returns:** Promise<{ permission: boolean; }> - --------------------- - - ### isListening() ```typescript @@ -188,17 +173,6 @@ This method will check if speech recognition is listening. -------------------- -### requestPermission() - -```typescript -requestPermission() => Promise -``` - -This method will prompt the user for audio permission. - --------------------- - - ### checkPermissions() ```typescript diff --git a/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java b/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java index 4301529..fa63ebd 100644 --- a/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java +++ b/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java @@ -114,28 +114,11 @@ public void getSupportedLanguages(PluginCall call) { bridge.getActivity().sendOrderedBroadcast(detailsIntent, null, languageReceiver, null, Activity.RESULT_OK, null, null); } - @PluginMethod - public void hasPermission(PluginCall call) { - call.resolve(new JSObject().put("permission", hasAudioPermissions(RECORD_AUDIO_PERMISSION))); - } - @PluginMethod public void isListening(PluginCall call) { call.resolve(new JSObject().put("listening", SpeechRecognition.this.listening)); } - @PluginMethod - public void requestPermission(PluginCall call) { - if (!hasAudioPermissions(RECORD_AUDIO_PERMISSION)) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { - bridge.getActivity().requestPermissions(new String[] { RECORD_AUDIO_PERMISSION }, REQUEST_CODE_PERMISSION); - call.resolve(); - } else { - call.resolve(); - } - } - } - @ActivityCallback private void listeningResult(PluginCall call, ActivityResult result) { if (call == null) { diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index 93eea0c..99c9075 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -164,24 +164,6 @@ public class SpeechRecognition: CAPPlugin { ]) } - @objc func hasPermission(_ call: CAPPluginCall) { - let status: SFSpeechRecognizerAuthorizationStatus = SFSpeechRecognizer.authorizationStatus() - let speechAuthGranted: Bool = (status == SFSpeechRecognizerAuthorizationStatus.authorized) - - if !speechAuthGranted { - call.resolve([ - "permission": false - ]) - return - } - - AVAudioSession.sharedInstance().requestRecordPermission { (granted: Bool) in - call.resolve([ - "permission": granted - ]) - } - } - @objc override public func checkPermissions(_ call: CAPPluginCall) { let status: SFSpeechRecognizerAuthorizationStatus = SFSpeechRecognizer.authorizationStatus() let permission: String @@ -198,48 +180,6 @@ public class SpeechRecognition: CAPPlugin { call.resolve(["speechRecognition": permission]) } - @objc func requestPermission(_ call: CAPPluginCall) { - SFSpeechRecognizer.requestAuthorization { (status: SFSpeechRecognizerAuthorizationStatus) in - DispatchQueue.main.async { - var speechAuthGranted: Bool = false - - switch status { - case SFSpeechRecognizerAuthorizationStatus.authorized: - speechAuthGranted = true - break - - case SFSpeechRecognizerAuthorizationStatus.denied: - call.reject(self.messageAccessDenied) - break - - case SFSpeechRecognizerAuthorizationStatus.restricted: - call.reject(self.messageRestricted) - break - - case SFSpeechRecognizerAuthorizationStatus.notDetermined: - call.reject(self.messageNotDetermined) - break - - @unknown default: - call.reject(self.messageUnknown) - } - - if !speechAuthGranted { - return - } - - AVAudioSession.sharedInstance().requestRecordPermission { (granted: Bool) in - if granted { - call.resolve() - } else { - call.reject(self.messageAccessDeniedMicrophone) - } - } - } - - } - } - @objc override public func requestPermissions(_ call: CAPPluginCall) { SFSpeechRecognizer.requestAuthorization { (status: SFSpeechRecognizerAuthorizationStatus) in DispatchQueue.main.async { diff --git a/src/definitions.ts b/src/definitions.ts index 58fe047..1b0bb8d 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -45,15 +45,6 @@ export interface SpeechRecognitionPlugin { * @returns languages - array string of languages */ getSupportedLanguages(): Promise<{ languages: any[] }>; - /** - * This method will check for audio permissions. - * @param none - * @returns permission - boolean true/false if permissions are granted - * - * @deprecated use `checkPermissions()` - */ - hasPermission(): Promise<{ permission: boolean }>; - /** * This method will check if speech recognition is listening. * @param none @@ -62,14 +53,6 @@ export interface SpeechRecognitionPlugin { * @since 5.1.0 */ isListening(): Promise<{ listening: boolean }>; - /** - * This method will prompt the user for audio permission. - * @param none - * @returns void - * - * @deprecated use `requestPermissions()` - */ - requestPermission(): Promise; /** * Check the speech recognition permission. *