diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 1d38a4db5..4090eeb04 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -93,7 +93,7 @@ NSContactsUsageDescription Signal uses your contacts to find users you know. We do not store your contacts on the server. NSMicrophoneUsageDescription - Signal needs access to your microphone to make and receive phone calls. + Signal needs access to your microphone to make and receive phone calls and record voice messages. NSPhotoLibraryUsageDescription Signal will let you choose which photos from your library to send. UIAppFonts diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index 28057efc6..361cf70d5 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -3105,6 +3105,29 @@ typedef enum : NSUInteger { #pragma mark - Audio +- (void)requestRecordingVoiceMemo +{ + OWSAssert([NSThread isMainThread]); + + __weak typeof(self) weakSelf = self; + [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) { + dispatch_async(dispatch_get_main_queue(), ^{ + __strong typeof(self) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + + if (granted) { + [strongSelf startRecordingVoiceMemo]; + } else { + DDLogInfo(@"%@ we do not have recording permission.", self.tag); + [strongSelf cancelVoiceMemo]; + [OWSAlerts showNoMicrophonePermissionAlert]; + } + }); + }]; +} + - (void)startRecordingVoiceMemo { OWSAssert([NSThread isMainThread]); @@ -3122,6 +3145,8 @@ typedef enum : NSUInteger { // Setup audio session AVAudioSession *session = [AVAudioSession sharedInstance]; + OWSAssert(session.recordPermission == AVAudioSessionRecordPermissionGranted); + NSError *error; [session setCategory:AVAudioSessionCategoryRecord error:&error]; if (error) { @@ -3162,13 +3187,6 @@ typedef enum : NSUInteger { OWSAssert(0); return; } - - if (session.recordPermission != AVAudioSessionRecordPermissionGranted) { - DDLogInfo(@"%@ we do not have recording permission.", self.tag); - [self cancelVoiceMemo]; - [OWSAlerts showNoMicrophonePermissionAlert]; - return; - } } - (void)endRecordingVoiceMemo @@ -3557,7 +3575,7 @@ typedef enum : NSUInteger { [((OWSMessagesInputToolbar *)self.inputToolbar)showVoiceMemoUI]; AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); - [self startRecordingVoiceMemo]; + [self requestRecordingVoiceMemo]; } - (void)voiceMemoGestureDidEnd diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 2f5ef8bda..5c40c61bf 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -182,7 +182,7 @@ "BLOCK_OFFER_ACTIONSHEET_TITLE_FORMAT" = "Block %@?"; /* 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."; +"CALL_AUDIO_PERMISSION_MESSAGE" = "Signal requires access to your microphone to make calls and record voice messages. You can grant this permission in the Settings app."; /* Alert title when calling and permissions for microphone are missing */ "CALL_AUDIO_PERMISSION_TITLE" = "Microphone Access Required";