Skip to content

Commit

Permalink
fix(ios): UI issues with main thread and added alert for permission. (#…
Browse files Browse the repository at this point in the history
…184)

* iOS: Fixed UI issues with main thread and added alert for permission.
  - solved critical error connected with performing the UI operation on the non-UI thread.
  - added the alert dialog for the Microphone permission, if it is not granted.
* chore: use localizable strings for mic permission alert
* chore: add blank new line on localizable strings files
* chore: updated French Localizable.strings

---------

Co-authored-by: Erisu <erisu@apache.org>
  • Loading branch information
BardRedStar and erisu authored Aug 14, 2023
1 parent 24a1b12 commit 1796d0a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
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 @@ -25,3 +25,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" = "límite de grabación alcanzado";
// accessibility hint for display of recorded elapsed time
"recorded time in minutes and seconds" = "tiempo de grabación 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/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
"timed recording complete" = "limite d'enregistrement atteinte";
// accessibility hint for display of recorded elapsed time
"recorded time in minutes and seconds" = "temps d'enregistrement en minutes et secondes";
// Access denied
"Access denied" = "Accès refusé";
// Microphone access has been prohibited
"Access to the microphone has been prohibited. Please enable it in the Settings app to continue." = "L'accès au micro a été interdit. Veuillez l'activer dans l'application Paramètres pour continuer.";
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 @@ -25,3 +25,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.";
40 changes: 30 additions & 10 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,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 @@ -814,6 +811,9 @@ - (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:[weakSelf.duration doubleValue]];
Expand All @@ -833,13 +833,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 @@ -879,6 +881,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

0 comments on commit 1796d0a

Please sign in to comment.