Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Fixed UI issues with main thread and added alert for permission. #184

Merged
merged 5 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ios/CDVCapture.bundle/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@
"timed recording complete" = "programmierte Aufnahme beendet";
// accessibility hint for display of recorded elapsed time
"recorded time in minutes and seconds" = "aufgenommene Zeit in Minuten und Sekunden";
// Access denied
"Access denied" = "Zugriff abgelehnt";
// Microphone access has been prohibited
"Access to the microphone has been prohibited. Please enable it in the Settings app to continue." = "Der Zugriff auf das Mikrofon wurde verboten. Bitte aktivieren Sie es in der Einstellungen-App, um fortzufahren.";
4 changes: 4 additions & 0 deletions src/ios/CDVCapture.bundle/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
"timed recording complete" = "timed recording complete";
// accessibility hint for display of recorded elapsed time
"recorded time in minutes and seconds" = "recorded time in minutes and seconds";
// Access denied
"Access denied" = "Access denied";
// Microphone access has been prohibited
"Access to the microphone has been prohibited. Please enable it in the Settings app to continue." = "Access to the microphone has been prohibited. Please enable it in the Settings app to continue.";
4 changes: 4 additions & 0 deletions src/ios/CDVCapture.bundle/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
"timed recording complete" = "tiempo de grabación completo";
// accessibility hint for display of recorded elapsed time
"recorded time in minutes and seconds" = "tiempo registrado en minutos y segundos";
// Access denied
"Access denied" = "Acceso denegado";
// Microphone access has been prohibited
"Access to the microphone has been prohibited. Please enable it in the Settings app to continue." = "Se ha prohibido el acceso al micrófono. Habilítelo en la aplicación Configuración para continuar.";
4 changes: 4 additions & 0 deletions src/ios/CDVCapture.bundle/se.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@
"timed recording complete" = "inspelning har avslutad";
// accessibility hint for display of recorded elapsed time
"recorded time in minutes and seconds" = "inspelad tid in minuter och sekund";
// Access denied
"Access denied" = "Tillträde beviljas ej";
// Microphone access has been prohibited
"Access to the microphone has been prohibited. Please enable it in the Settings app to continue." = "Tillgång till mikrofonen har förbjudits. Aktivera det i appen Inställningar för att fortsätta.";
42 changes: 31 additions & 11 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,6 @@ - (void)processButton:(id)sender
// view cleanup will occur in audioRecordingDidFinishRecording
} else {
// begin recording
[self.recordButton setImage:stopRecordImage forState:UIControlStateNormal];
self.recordButton.accessibilityTraits &= ~[self accessibilityTraits];
[self.recordingView setHidden:NO];
__block NSError* error = nil;

__weak CDVAudioRecorderViewController* weakSelf = self;
Expand All @@ -826,9 +823,12 @@ - (void)processButton:(id)sender
weakSelf.errorCode = CAPTURE_INTERNAL_ERR;
[weakSelf dismissAudioView:nil];
} else {
[weakSelf.recordButton setImage:weakSelf.stopRecordImage forState:UIControlStateNormal];
weakSelf.recordButton.accessibilityTraits &= ~[self accessibilityTraits];
[weakSelf.recordingView setHidden:NO];
if (weakSelf.duration) {
weakSelf.isTimed = true;
[weakSelf.avRecorder recordForDuration:[duration doubleValue]];
[weakSelf.avRecorder recordForDuration:[weakSelf.duration doubleValue]];
} else {
[weakSelf.avRecorder record];
}
Expand All @@ -845,13 +845,15 @@ - (void)processButton:(id)sender
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.avSession performSelector:rrpSel withObject:^(BOOL granted){
if (granted) {
startRecording();
} else {
NSLog(@"Error creating audio session, microphone permission denied.");
weakSelf.errorCode = CAPTURE_INTERNAL_ERR;
[weakSelf dismissAudioView:nil];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
startRecording();
} else {
NSLog(@"Error creating audio session, microphone permission denied.");
weakSelf.errorCode = CAPTURE_INTERNAL_ERR;
[weakSelf showMicrophonePermissionAlert];
}
});
}];
#pragma clang diagnostic pop
} else {
Expand Down Expand Up @@ -891,6 +893,24 @@ - (void)stopRecordingCleanup
}
}

- (void) showMicrophonePermissionAlert {
UIAlertController* controller =
[UIAlertController alertControllerWithTitle:PluginLocalizedString(captureCommand, @"Access denied", nil)
message:PluginLocalizedString(captureCommand, @"Access to the microphone has been prohibited. Please enable it in the Settings app to continue.", nil)
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* actionOk = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[controller addAction:actionOk];

UIAlertAction* actionSettings = [UIAlertAction actionWithTitle:@"Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:[NSDictionary dictionary] completionHandler:nil];
}];
[controller addAction:actionSettings];

__weak CDVAudioRecorderViewController* weakSelf = self;
[weakSelf presentViewController:controller animated:true completion:nil];
}

- (void)dismissAudioView:(id)sender
{
// called when done button pressed or when error condition to do cleanup and remove view
Expand Down