From 737a9880b6412ab39750017f24de0e60a003a319 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 10 Jul 2025 11:42:03 +0200 Subject: [PATCH] Check permissions before displaying the PermissionsFragment view --- Linphone/UI/Welcome/WelcomeView.swift | 3 +++ Linphone/Utils/PermissionManager.swift | 29 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Linphone/UI/Welcome/WelcomeView.swift b/Linphone/UI/Welcome/WelcomeView.swift index c207a9518..31433f634 100644 --- a/Linphone/UI/Welcome/WelcomeView.swift +++ b/Linphone/UI/Welcome/WelcomeView.swift @@ -149,6 +149,9 @@ struct WelcomeView: View { .clipped() } .frame(minHeight: geometry.size.height) + .onAppear { + PermissionManager.shared.havePermissionsAlreadyBeenRequested() + } } func setupAppearance() { diff --git a/Linphone/Utils/PermissionManager.swift b/Linphone/Utils/PermissionManager.swift index dab08971b..61372987f 100644 --- a/Linphone/Utils/PermissionManager.swift +++ b/Linphone/Utils/PermissionManager.swift @@ -126,4 +126,33 @@ class PermissionManager: ObservableObject { self.allPermissionsHaveBeenDisplayed = true } } + + func havePermissionsAlreadyBeenRequested() { + let cameraStatus = AVCaptureDevice.authorizationStatus(for: .video) + let micStatus = AVAudioSession.sharedInstance().recordPermission + let photoStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite) + let contactsStatus = CNContactStore.authorizationStatus(for: .contacts) + + let notifGroup = DispatchGroup() + var notifStatus: UNAuthorizationStatus = .notDetermined + + notifGroup.enter() + UNUserNotificationCenter.current().getNotificationSettings { settings in + notifStatus = settings.authorizationStatus + notifGroup.leave() + } + + notifGroup.notify(queue: .main) { + let allAlreadyRequested = cameraStatus != .notDetermined && + micStatus != .undetermined && + photoStatus != .notDetermined && + contactsStatus != .notDetermined && + notifStatus != .notDetermined + + if allAlreadyRequested { + self.allPermissionsHaveBeenDisplayed = true + } + } + } + }