Loading src/ios/CDVSound.m +29 −5 Changes for src/ios/CDVSound.m: 29 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -527,10 +527,11 @@ NSString* mediaId = [command.arguments objectAtIndex:0]; CDVAudioFile* audioFile = [self audioFileForResource:[command.arguments objectAtIndex:1] withId:mediaId doValidation:YES forRecording:YES]; NSString* jsString = nil; NSString* errorMsg = @""; __block NSString* jsString = nil; __block NSString* errorMsg = @""; if ((audioFile != nil) && (audioFile.resourceURL != nil)) { void (^startRecording)(void) = ^{ NSError* __autoreleasing error = nil; if (audioFile.recorder != nil) { Loading Loading @@ -576,15 +577,38 @@ } jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]]; } }; SEL rrpSel = NSSelectorFromString(@"requestRecordPermission:"); if ([self hasAudioSession] && [self.avSession respondsToSelector:rrpSel]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [self.avSession performSelector:rrpSel withObject:^(BOOL granted){ if (granted) { startRecording(); } else { NSString* msg = @"Error creating audio session, microphone permission denied."; NSLog(@"%@", msg); audioFile.recorder = nil; if (self.avSession) { [self.avSession setActive:NO error:nil]; } jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:msg]]; [self.commandDelegate evalJs:jsString]; } }]; #pragma clang diagnostic pop } else { startRecording(); } } else { // file did not validate NSString* errorMsg = [NSString stringWithFormat:@"Could not record audio at '%@'", audioFile.resourcePath]; jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]]; } if (jsString) { [self.commandDelegate evalJs:jsString]; } return; } - (void)stopRecordingAudio:(CDVInvokedUrlCommand*)command Loading Loading
src/ios/CDVSound.m +29 −5 Changes for src/ios/CDVSound.m: 29 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -527,10 +527,11 @@ NSString* mediaId = [command.arguments objectAtIndex:0]; CDVAudioFile* audioFile = [self audioFileForResource:[command.arguments objectAtIndex:1] withId:mediaId doValidation:YES forRecording:YES]; NSString* jsString = nil; NSString* errorMsg = @""; __block NSString* jsString = nil; __block NSString* errorMsg = @""; if ((audioFile != nil) && (audioFile.resourceURL != nil)) { void (^startRecording)(void) = ^{ NSError* __autoreleasing error = nil; if (audioFile.recorder != nil) { Loading Loading @@ -576,15 +577,38 @@ } jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]]; } }; SEL rrpSel = NSSelectorFromString(@"requestRecordPermission:"); if ([self hasAudioSession] && [self.avSession respondsToSelector:rrpSel]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [self.avSession performSelector:rrpSel withObject:^(BOOL granted){ if (granted) { startRecording(); } else { NSString* msg = @"Error creating audio session, microphone permission denied."; NSLog(@"%@", msg); audioFile.recorder = nil; if (self.avSession) { [self.avSession setActive:NO error:nil]; } jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:msg]]; [self.commandDelegate evalJs:jsString]; } }]; #pragma clang diagnostic pop } else { startRecording(); } } else { // file did not validate NSString* errorMsg = [NSString stringWithFormat:@"Could not record audio at '%@'", audioFile.resourcePath]; jsString = [NSString stringWithFormat:@"%@(\"%@\",%d,%@);", @"cordova.require('org.apache.cordova.core.media.Media').onStatus", mediaId, MEDIA_ERROR, [self createMediaErrorWithCode:MEDIA_ERR_ABORTED message:errorMsg]]; } if (jsString) { [self.commandDelegate evalJs:jsString]; } return; } - (void)stopRecordingAudio:(CDVInvokedUrlCommand*)command Loading