@ -46,7 +46,34 @@ import Foundation
return false
}
callUIAdapter . startAndShowOutgoingCall ( recipientId : recipientId )
// C h e c k f o r m i c r o p h o n e p e r m i s s i o n s
// A l t e r n a t i v e w a y w i t h o u t p r o m p t i n g f o r p e r m i s s i o n s :
// i f A V A u d i o S e s s i o n . s h a r e d I n s t a n c e ( ) . r e c o r d P e r m i s s i o n ( ) = = . d e n i e d {
AVAudioSession . sharedInstance ( ) . requestRecordPermission { isGranted in
// H e r e t h e p e r m i s s i o n s a r e e i t h e r g r a n t e d o r d e n i e d
guard isGranted = = true else {
Logger . warn ( " \( self . TAG ) aborting due to missing microphone permissions. " )
self . showNoMicrophonePermissionAlert ( )
return
}
callUIAdapter . startAndShowOutgoingCall ( recipientId : recipientId )
}
return true
}
// / C l e a n u p a n d p r e s e n t a l e r t f o r n o p e r m i s s i o n s
private func showNoMicrophonePermissionAlert ( ) {
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 : . 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 ) ! )
}
alertController . addAction ( dismissAction )
alertController . addAction ( settingsAction )
UIApplication . shared . frontmostViewController ? . present ( alertController , animated : true , completion : nil )
}
}