nstudio / nativescript-audio

:microphone: NativeScript plugin to record and play audio :musical_note:
Other
150 stars 104 forks source link

Request: handle iOS permissions for recording #59

Open shripalsoni04 opened 7 years ago

shripalsoni04 commented 7 years ago

First of all 👍 for this awesome plugin. Thanks for creating this.

I found that on iOS, if user deny the permission to record audio using microphone, the promise of start method is not getting resolved or rejected.

It will be great if we can have some intimation if user has given permission or not, to take further actions.

I quickly looked into the code. I think it will satisfy this requirement if we just reject the promise if permission is denied as follows:

src/ios/recorder.ts

public start(options: AudioRecorderOptions): Promise<any> {
    return new Promise((resolve, reject) => {
       this._recordingSession.requestRecordPermission((allowed: boolean) => {
          if (allowed) {
                 ...
                resolve();
                ...
          } else {
              reject('Permission Denied');
          }
    });
 });
}

If there is already some way to get intimation that user has denied the permission, then please let me know. It will be very helpful to me.

Thanks.

bradmartin commented 7 years ago

I'd like to get permission requests added to the plugin for recording and then gracefully handling the promise. @shripalsoni04 - you want to work on a PR for this. For android we can include the dep. of nativescript-permissions to keep it simple. Just a public method requestRecordingPermission would be sufficient on android. I know iOS perms are different, you might be more familiar with the approach there 😄 . Let me know if you want to work on this and if you have any questions or need help.