0

I use new API for requesting of access for an assets library of a user:

PHPhotoLibrary.requestAuthorization(for: .readWrite) { 
                [weak self] (status:PHAuthorizationStatus) in
                print("called");
            }

iOS displays alert with access levels:
Alert with access levels

If the user selects Select Photos..., iOS will show a picker:
the images picker

If user swipes down on a title of the picker, the photos library will not call the handler block.

Implementation of the photoLibraryDidChange

 func photoLibraryDidChange(_ changeInstance: (PHChange)) {
        guard let fetchResult = self.fetchResult else {
            return
        }
        if changeInstance.changeDetails(for: fetchResult) != nil {
            DispatchQueue.main.async {
                self.delegate?.photosLibraryChanged(self)
            }
        }
    }

Does someone faced with this situation? And how I can fix it?

Example: https://github.com/K-Be/NewInPhotoKitInIOS14

Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40
  • But you, as a user, did not request authorisation yet, because no photo selected, actually you performed cancel (by swiping down), so no callback performed. By my vision it behaves as expected. – Asperi Dec 18 '20 at 03:54
  • if application will be relaunched, the access level will be limited :( – Andrew Romanov Dec 18 '20 at 03:55
  • Also, If I asks access level in Curren session, it also will be limited. But in current logic, I wait wile the user makes decision about the access level for my application. – Andrew Romanov Dec 18 '20 at 03:58
  • Also, if the user preformed cancel by press the cancel button, the handler will be called. – Andrew Romanov Dec 18 '20 at 04:05
  • @AndrewRomanov have you implemented `photoLibraryDidChange` method? The most common mistake is to PHPhotoLibrary.requestAuthorization and do not implement `photoLibraryDidChange` method. – Leo Dabus Dec 18 '20 at 04:48
  • Yes, I have. I've implemented it in the data source. – Andrew Romanov Dec 18 '20 at 04:49
  • Edit your question and show your implementation. – Leo Dabus Dec 18 '20 at 04:50
  • Did you call `PHPhotoLibrary.shared().register(self)` in viewDidLoad? Does your controller conform to `PHPhotoLibraryChangeObserver`? – Leo Dabus Dec 18 '20 at 04:52
  • Yeap. But it does not matter. – Andrew Romanov Dec 18 '20 at 04:53
  • It does. If you request authorization it will change the assets available. You said that if you quit and open again the access level changes – Leo Dabus Dec 18 '20 at 04:55
  • it is interesting, I'll try to check it :) – Andrew Romanov Dec 18 '20 at 04:56
  • this might help https://developer.apple.com/documentation/photokit/phphotolibrarychangeobserver – Leo Dabus Dec 18 '20 at 04:57
  • photoLibraryDidChange is not called in this case :( – Andrew Romanov Dec 18 '20 at 05:03
  • You did check if it is equal to nil but did not get the result. `if let changes = changeInstance.changeDetails(for: fetchResult) {` `// Keep the new fetch result for future use.` `fetchResult = changes.fetchResultAfterChanges` – Leo Dabus Dec 18 '20 at 05:04
  • I inserted break point there. – Andrew Romanov Dec 18 '20 at 05:05
  • I haven't implemented limited authorization but your `photoLibraryDidChange` implementation doesn't look correct – Leo Dabus Dec 18 '20 at 05:06
  • Sorry, it is other discussion (about implementation of photoLibraryDidChange), and I can tell why it should asks changeDetails and so on, but in other discussion. Also for local check, I add subscription to changes in next line where I ask access. – Andrew Romanov Dec 18 '20 at 05:09
  • you are not fetching Assets inside your closure after requesting authorization – Leo Dabus Dec 18 '20 at 05:09
  • In the closure Access notify delegate about results, and delegate asks DataSource to fetch assets. (I do not like BVC, and prefer to divide an application to blocks, I you want I can show how it works). – Andrew Romanov Dec 18 '20 at 05:11

0 Answers0