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(
info: ConfirmationModal.Info(
let confirmationModal: ConfirmationModal = ConfirmationModal( title: "permissionsRequired".localized(),
info: ConfirmationModal.Info( body: .text(
title: "permissionsRequired".localized(), "permissionsMicrophoneAccessRequiredIos"
body: .text( .put(key: "app_name", value: Constants.app_name)
"permissionsMicrophoneAccessRequiredIos" .localized()
.put(key: "app_name", value: Constants.app_name) ),
.localized() confirmTitle: "sessionSettings".localized(),
), dismissOnConfirm: false,
confirmTitle: "sessionSettings".localized(), onConfirm: { [weak presentingViewController] _ in
dismissOnConfirm: false, presentingViewController?.dismiss(animated: true, completion: {
onConfirm: { [weak presentingViewController] _ in UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
presentingViewController?.dismiss(animated: true, completion: { })
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: }
onNotGranted?()
AVAudioSession.sharedInstance().requestRecordPermission { _ in } if #available(iOS 17.0, *) {
switch AVAudioApplication.shared.recordPermission {
default: break case .granted: break
case .denied: handlePermissionDenied()
case .undetermined:
onNotGranted?()
AVAudioSession.sharedInstance().requestRecordPermission { _ in }
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