iosswiftcameraphoto

How to detect when the "Select More Photos" popup is dismissed in iOS?


I'm working on an iOS app that uses the camera to scan documents. When the user has limited photo library access, iOS shows a system popup with options like “Select More Photos” and “Keep Current Selection”. And i can't know when the popup is dissmissed

enter image description here

Here's what I've tried:

Is there any reliable way to detect when the "Select More Photos" system popup is dismissed? I don’t need to know which button was tapped, just when it disappears. Any workarounds or private class detection (as long as App Store safe) are also appreciated.


Solution

  • In iOS 15 and later, Apple introduced limited photo library access, allowing users to grant access to selected photos instead of the entire library. When the system popup appears with options like "Select More Photos" or "Keep Current Selection", the app does not receive a direct callback when the popup is dismissed.

    Solution: Detect Changes in Authorization Status You can use PHPhotoLibrary's register(_: ) method to observe changes in the user's photo library access.

    Steps: Register an observer for PHPhotoLibraryChangeObserver.

    Check for changes in authorization status using PHPhotoLibrary.authorizationStatus(for:).

    Reload UI when access is changed.

    func photoLibraryDidChange(_ changeInstance: PHChange) {
            DispatchQueue.main.async {
                print("Photo library access may have changed!")
                self.checkPhotoLibraryPermission()
            }
        }
    
        private func checkPhotoLibraryPermission() {
            let status = PHPhotoLibrary.authorizationStatus(for: .readWrite)
            switch status {
            case .authorized:
                print("Full access granted")
            case .limited:
                print("Limited access granted")
            case .denied, .restricted:
                print("Access denied")
            case .notDetermined:
                print("User has not made a choice")
            @unknown default:
                print("Unknown status")
            }
        }