From 70efb5e9ecb0fd8888dfdcb98816a605ac0be59c Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sun, 26 Mar 2017 15:50:51 +0300 Subject: [PATCH 1/2] Check microphone permissions before starting a call --- Signal/src/call/OutboundCallInitiator.swift | 30 ++++++++++++++++++- .../translations/en.lproj/Localizable.strings | 17 ++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) 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."; From da8596c1bad496c81bdfaae29af0f6d712343384 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 14 Apr 2017 10:29:29 -0400 Subject: [PATCH 2/2] Check microphone permissions: Clean up * copy tweaks * use "settings" instead of "privacy settings" for button text * include comments in NSLocalizedString param so they can be extracted with genstrings * style dismiss action as "cancel" // FREEBIE --- Signal/src/call/OutboundCallInitiator.swift | 11 +++++------ Signal/translations/en.lproj/Localizable.strings | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Signal/src/call/OutboundCallInitiator.swift b/Signal/src/call/OutboundCallInitiator.swift index ace6715b0..c4e76661f 100644 --- a/Signal/src/call/OutboundCallInitiator.swift +++ b/Signal/src/call/OutboundCallInitiator.swift @@ -46,7 +46,6 @@ import Foundation return false } - // Check for microphone permissions // Alternative way without prompting for permissions: // if AVAudioSession.sharedInstance().recordPermission() == .denied { @@ -61,15 +60,15 @@ import Foundation } 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 alertTitle = NSLocalizedString("CALL_AUDIO_PERMISSION_TITLE", comment:"Alert title when calling and permissions for microphone are missing") + let alertMessage = NSLocalizedString("CALL_AUDIO_PERMISSION_MESSAGE", comment:"Alert message when calling and permissions for microphone are missing") 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 dismissAction = UIAlertAction(title: dismiss, style: .cancel) + let settingsString = NSLocalizedString("OPEN_SETTINGS_BUTTON", comment: "Button text which opens the settings app") let settingsAction = UIAlertAction(title: settingsString, style: .default) { _ in UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!) } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index da4e6c0c6..ed1710d77 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -160,11 +160,11 @@ /* 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 message when calling and permissions for microphone are missing */ +"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"; +/* Alert title when calling and permissions for microphone are missing */ +"CALL_AUDIO_PERMISSION_TITLE" = "Microphone Access Required"; /* Accessibilty label for placing call button */ "CALL_LABEL" = "Call"; @@ -184,8 +184,7 @@ /* 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 - Settings button text */ +/* Label for button that shows the privacy settings */ "CALL_VIEW_SETTINGS_NAG_SHOW_CALL_SETTINGS" = "Show Privacy Settings"; /* notification action */