Skip to content

Commit

Permalink
feat!: Remove deprecated permission methods (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jun 7, 2024
1 parent 8e2f62b commit 77d89b8
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 120 deletions.
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-)
Expand Down Expand Up @@ -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:** <code>Promise&lt;{ permission: boolean; }&gt;</code>

--------------------


### isListening()

```typescript
Expand All @@ -188,17 +173,6 @@ This method will check if speech recognition is listening.
--------------------


### requestPermission()

```typescript
requestPermission() => Promise<void>
```

This method will prompt the user for audio permission.

--------------------


### checkPermissions()

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
60 changes: 0 additions & 60 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
17 changes: 0 additions & 17 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<void>;
/**
* Check the speech recognition permission.
*
Expand Down

0 comments on commit 77d89b8

Please sign in to comment.