further refactor to use latest API

pull/1061/head
Ryan ZHAO 9 months ago
parent 403ca8c10c
commit 47f9984d33

@ -323,7 +323,7 @@ extension ConversationVC:
Permissions.requestMicrophonePermissionIfNeeded() Permissions.requestMicrophonePermissionIfNeeded()
if AVAudioSession.sharedInstance().recordPermission != .granted { if !Permissions.hasMicrophonePermission {
SNLog("Proceeding without microphone access. Any recorded video will be silent.") SNLog("Proceeding without microphone access. Any recorded video will be silent.")
} }

@ -169,7 +169,7 @@ final class CallMessageCell: MessageCell {
!Storage.shared[.areCallsEnabled] !Storage.shared[.areCallsEnabled]
) || ( ) || (
messageInfo.state == .permissionDeniedMicrophone && messageInfo.state == .permissionDeniedMicrophone &&
AVAudioSession.sharedInstance().recordPermission != .granted !Permissions.hasMicrophonePermission
) )
) )
infoImageViewWidthConstraint.constant = (shouldShowInfoIcon ? CallMessageCell.iconSize : 0) infoImageViewWidthConstraint.constant = (shouldShowInfoIcon ? CallMessageCell.iconSize : 0)
@ -230,7 +230,7 @@ final class CallMessageCell: MessageCell {
!Storage.shared[.areCallsEnabled] !Storage.shared[.areCallsEnabled]
) || ( ) || (
messageInfo.state == .permissionDeniedMicrophone && messageInfo.state == .permissionDeniedMicrophone &&
AVAudioSession.sharedInstance().recordPermission != .granted !Permissions.hasMicrophonePermission
) )
else { return } else { return }

@ -57,40 +57,54 @@ extension Permissions {
presentingViewController: UIViewController? = nil, presentingViewController: UIViewController? = nil,
onNotGranted: (() -> Void)? = nil onNotGranted: (() -> Void)? = nil
) { ) {
switch AVAudioSession.sharedInstance().recordPermission { let handlePermissionDenied: () -> Void = {
case .granted: break guard
case .denied: Singleton.hasAppContext,
guard let presentingViewController: UIViewController = (presentingViewController ?? Singleton.appContext.frontmostViewController)
Singleton.hasAppContext, else { return }
let presentingViewController: UIViewController = (presentingViewController ?? Singleton.appContext.frontmostViewController) onNotGranted?()
else { return }
onNotGranted?()
let confirmationModal: ConfirmationModal = ConfirmationModal( let confirmationModal: ConfirmationModal = ConfirmationModal(
info: ConfirmationModal.Info( info: ConfirmationModal.Info(
title: "permissionsRequired".localized(), title: "permissionsRequired".localized(),
body: .text( body: .text(
"permissionsMicrophoneAccessRequiredIos" "permissionsMicrophoneAccessRequiredIos"
.put(key: "app_name", value: Constants.app_name) .put(key: "app_name", value: Constants.app_name)
.localized() .localized()
), ),
confirmTitle: "sessionSettings".localized(), confirmTitle: "sessionSettings".localized(),
dismissOnConfirm: false, dismissOnConfirm: false,
onConfirm: { [weak presentingViewController] _ in onConfirm: { [weak presentingViewController] _ in
presentingViewController?.dismiss(animated: true, completion: { presentingViewController?.dismiss(animated: true, completion: {
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
}) })
}, },
afterClosed: { onNotGranted?() } afterClosed: { onNotGranted?() }
)
) )
presentingViewController.present(confirmationModal, animated: true, completion: nil) )
presentingViewController.present(confirmationModal, animated: true, completion: nil)
}
case .undetermined: if #available(iOS 17.0, *) {
onNotGranted?() switch AVAudioApplication.shared.recordPermission {
AVAudioSession.sharedInstance().requestRecordPermission { _ in } case .granted: break
case .denied: handlePermissionDenied()
case .undetermined:
onNotGranted?()
AVAudioSession.sharedInstance().requestRecordPermission { _ in }
default: break default: break
}
} else {
switch AVAudioSession.sharedInstance().recordPermission {
case .granted: break
case .denied: handlePermissionDenied()
case .undetermined:
onNotGranted?()
AVAudioSession.sharedInstance().requestRecordPermission { _ in }
default: break
}
} }
} }

Loading…
Cancel
Save