diff --git a/Signal/src/call/OutboundCallInitiator.swift b/Signal/src/call/OutboundCallInitiator.swift index 52dea9a40..ace6715b0 100644 --- a/Signal/src/call/OutboundCallInitiator.swift +++ b/Signal/src/call/OutboundCallInitiator.swift @@ -46,7 +46,35 @@ import Foundation return false } - callUIAdapter.startAndShowOutgoingCall(recipientId: recipientId) + + // Check for microphone permissions + // Alternative way without prompting for permissions: + // if AVAudioSession.sharedInstance().recordPermission() == .denied { + AVAudioSession.sharedInstance().requestRecordPermission { isGranted in + // Here the permissions are either granted or denied + guard isGranted == true else { + Logger.warn("\(self.TAG) aborting due to missing microphone permissions.") + self.showNoMicrophonePermissionAlert() + return + } + callUIAdapter.startAndShowOutgoingCall(recipientId: recipientId) + } return true } + + /// Cleanup and present alert for no permissions + private func showNoMicrophonePermissionAlert() { + let alertTitle = NSLocalizedString("CALL_AUDIO_PERMISSION_TITLE", comment:"Alert Title") + let alertMessage = NSLocalizedString("CALL_AUDIO_PERMISSION_MESSAGE", comment:"Alert message") + let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) + let dismiss = NSLocalizedString("DISMISS_BUTTON_TEXT", comment: "Generic short text for button to dismiss a dialog") + let dismissAction = UIAlertAction(title: dismiss, style: .default) + let settingsString = NSLocalizedString("CALL_VIEW_SETTINGS_NAG_SHOW_CALL_SETTINGS", comment: "Settings button text") + let settingsAction = UIAlertAction(title: settingsString, style: .default) { _ in + UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!) + } + alertController.addAction(dismissAction) + alertController.addAction(settingsAction) + UIApplication.shared.frontmostViewController?.present(alertController, animated: true, completion: nil) + } } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index eac2b6e1d..da4e6c0c6 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -55,7 +55,7 @@ /* Format string for file extension label in call interstitial view */ "ATTACHMENT_APPROVAL_FILE_EXTENSION_FORMAT" = "File type: %@"; -/* Format string for file size label in call interstitial view */ +/* Format string for file size label in call interstitial view. Embeds: {{file size as 'N mb' or 'N kb'}}. */ "ATTACHMENT_APPROVAL_FILE_SIZE_FORMAT" = "Size: %@"; /* Label for 'send' button in the 'attachment approval' dialog. */ @@ -160,6 +160,12 @@ /* Title format for action sheet that offers to block an unknown user.Embeds {{the unknown user's name or phone number}}. */ "BLOCK_OFFER_ACTIONSHEET_TITLE_FORMAT" = "Block %@?"; +/* Alert message */ +"CALL_AUDIO_PERMISSION_MESSAGE" = "Signal requires access to your microphone to make calls. You can grant this permission in the Settings app"; + +/* Alert Title */ +"CALL_AUDIO_PERMISSION_TITLE" = "Call failed"; + /* Accessibilty label for placing call button */ "CALL_LABEL" = "Call"; @@ -178,7 +184,8 @@ /* Label for button that dismiss the call view's settings nag. */ "CALL_VIEW_SETTINGS_NAG_NOT_NOW_BUTTON" = "Not Now"; -/* Label for button that shows the privacy settings */ +/* Label for button that shows the privacy settings + Settings button text */ "CALL_VIEW_SETTINGS_NAG_SHOW_CALL_SETTINGS" = "Show Privacy Settings"; /* notification action */ @@ -229,12 +236,6 @@ /* table cell label in conversation settings */ "CONVERSATION_SETTINGS_BLOCK_THIS_USER" = "Block this user"; -/* The message of the 'text message too large' alert. */ -"CONVERSATION_VIEW_TEXT_MESSAGE_TOO_LARGE_ALERT_MESSAGE" = "This message is too long to send."; - -/* The title of the 'text message too large' alert. */ -"CONVERSATION_VIEW_TEXT_MESSAGE_TOO_LARGE_ALERT_TITLE" = "Error"; - /* ActionSheet title */ "CORRUPTED_SESSION_DESCRIPTION" = "Resetting your session will allow you to receive future messages from %@, but it will not recover any already corrupted messages.";