最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - How to detect when the "Select More Photos" popup is dismissed in iOS? - Stack Overflow

programmeradmin6浏览0评论

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:

  • Listening to UIWindowDidBecomeHiddenNotification, but it doesn't fire when the popup is dismissed.
  • Using UIApplicationDidBecomeActiveNotification, it works when the popup is showing, but cant catch the event when the popup is dismissed
  • Checking viewWillAppear or viewDidAppear, but the popup is not presented modally on my view controller, so those methods don’t get called again.

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.

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:

  • Listening to UIWindowDidBecomeHiddenNotification, but it doesn't fire when the popup is dismissed.
  • Using UIApplicationDidBecomeActiveNotification, it works when the popup is showing, but cant catch the event when the popup is dismissed
  • Checking viewWillAppear or viewDidAppear, but the popup is not presented modally on my view controller, so those methods don’t get called again.

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.

Share Improve this question edited Mar 23 at 10:03 Thư Nguyễn Công asked Mar 21 at 8:30 Thư Nguyễn CôngThư Nguyễn Công 112 bronze badges 3
  • 3 You would probably be better of putting your efforts into adopting PHPickerViewController. The user doesn't need to provide any photo library access and does not get a prompt for photo library access. It is a much better solution where you simply need the user to provide one or more photos to your app. See also developer.apple/videos/play/wwdc2020/10652 – Paulw11 Commented Mar 21 at 8:47
  • Thanks a lot for suggestion, i really appreciate it. I do need photo library access in this flow though, so i still wanna handle that popup properly. – Thư Nguyễn Công Commented Mar 21 at 8:59
  • Then can you use this? – Paulw11 Commented Mar 21 at 9:54
Add a comment  | 

1 Answer 1

Reset to default 1

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")
        }
    }
发布评论

评论列表(0)

  1. 暂无评论