PhotoKit: Can't access user's albums?

Using Xcode 13 beta 4, I seem to have lost the ability to access user-created photo albums with PhotoKit (via PHAssetCollection.fetchAssetCollections). When I request albums of the type .smartAlbum, I get all the Smart Albums. However when I request .album, I get 0 results. Has anyone else run into this?

Here's some example code:

import SwiftUI
import Photos

struct ContentView: View {
	@State var status: PHAuthorizationStatus = PHPhotoLibrary
		.authorizationStatus(for: .readWrite)

	private static var collectionOptions: PHFetchOptions {
		let reverseChron = PHFetchOptions()
		reverseChron.sortDescriptors = [NSSortDescriptor(keyPath: \PHAssetCollection.endDate, ascending: false)]
		return reverseChron
	}

    var body: some View {
		VStack {
			Text("Welcome!")
				.padding()
			if status == .authorized {
				Button("Load photos") {
					let userAlbums = PHAssetCollection.fetchAssetCollections(
						with: .album,
						subtype: .any,
						options: ContentView.collectionOptions
					)
					print("List of albums:")
					for i in 0..<userAlbums.count {
						let album = userAlbums[i]
						print(album.localizedTitle ?? "[No title]")
					}
				}
			}
		}.onAppear() {
			PHPhotoLibrary.requestAuthorization(for: .readWrite) { aStatus in
					  status = aStatus
				  }
			  }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Edit: filed as FB9477907

Accepted Reply

Thanks for filing the feedback! Are you still seeing this issue in the latest betas (Developer Seed 5)? A fix was included in those versions to correct this bug where apps that have .readWrite access to the photo library were not able to fetch user albums.

  • Yes! It looks like this has been resolved, but I'm still seeing an ominous warning in the console which seems like it might be related:

    2021-08-17 10:41:33.492656-0500 Mattebox[22718:3478646] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2021-08-17 10:41:33.501201-0500 Mattebox[22718:3478645] [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x282d60030> accessor:<<PAApplication 0x282343840> identifierType:auditToken identifier:{pid:22718, version:66702}> identifier:ZZZZZZZZZZZZZZZZ kind:intervalBegin timestampAdjustment:0 tccService:kTCCServicePhotos, error=Error Domain=PAErrorDomain Code=10 "Missing required entitlement" UserInfo={PAMissingEntitlement=com.apple.private.privacy.accounting.write}
  • With Xcode 13 the access is there, and I still see those two error messages occasionally, and the thing is they do not seem to be linked to any type of album. I have the following three lines going one after another:

        userCollections = PHCollectionList.fetchTopLevelUserCollections(with: nil)     allPhotos = PHAsset.fetchAssets(with: allPhotosOptions)     smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)

    I've played with the order they are placed in the code, and I always have the "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)" message after the first command whatever it is out of the three; and I always get the "[PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x280b27e10> accessor" message after the second command, whatever it is. The third command runs clean:

    2021-10-10 12:01:25.438540+0100 TD in SwiftUI[2306:680717] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2021-10-10 12:01:28.869695+0100 TD in SwiftUI[2306:680930] [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x282ee56e0> accessor:<<PAApplication 0x2820ec6e0> identifierType:auditToken identifier:{pid:2306, version:5997}> identifier:xxxxxxxxxxxxx kind:intervalEnd timestampAdjustment:0 tccService:kTCCServicePhotos, error=Error Domain=PAErrorDomain Code=11 "Possibly incomplete access interval automatically ended by daemon" (lldb) 

    So, the functionality seems to be there, but the error messages are thrown still but not consistently.

    Also, I can only see the messages when building for a physical device (8+) but not in the Simulator for the same model,

  • I have the same issue with XCode Version 13.4 (13F17a). When will the fix be released as an update?

Add a Comment

Replies

Seeing the same thing. Thank you for posting the code example.

Thanks for filing the feedback! Are you still seeing this issue in the latest betas (Developer Seed 5)? A fix was included in those versions to correct this bug where apps that have .readWrite access to the photo library were not able to fetch user albums.

  • Yes! It looks like this has been resolved, but I'm still seeing an ominous warning in the console which seems like it might be related:

    2021-08-17 10:41:33.492656-0500 Mattebox[22718:3478646] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2021-08-17 10:41:33.501201-0500 Mattebox[22718:3478645] [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x282d60030> accessor:<<PAApplication 0x282343840> identifierType:auditToken identifier:{pid:22718, version:66702}> identifier:ZZZZZZZZZZZZZZZZ kind:intervalBegin timestampAdjustment:0 tccService:kTCCServicePhotos, error=Error Domain=PAErrorDomain Code=10 "Missing required entitlement" UserInfo={PAMissingEntitlement=com.apple.private.privacy.accounting.write}
  • With Xcode 13 the access is there, and I still see those two error messages occasionally, and the thing is they do not seem to be linked to any type of album. I have the following three lines going one after another:

        userCollections = PHCollectionList.fetchTopLevelUserCollections(with: nil)     allPhotos = PHAsset.fetchAssets(with: allPhotosOptions)     smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)

    I've played with the order they are placed in the code, and I always have the "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)" message after the first command whatever it is out of the three; and I always get the "[PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x280b27e10> accessor" message after the second command, whatever it is. The third command runs clean:

    2021-10-10 12:01:25.438540+0100 TD in SwiftUI[2306:680717] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2021-10-10 12:01:28.869695+0100 TD in SwiftUI[2306:680930] [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x282ee56e0> accessor:<<PAApplication 0x2820ec6e0> identifierType:auditToken identifier:{pid:2306, version:5997}> identifier:xxxxxxxxxxxxx kind:intervalEnd timestampAdjustment:0 tccService:kTCCServicePhotos, error=Error Domain=PAErrorDomain Code=11 "Possibly incomplete access interval automatically ended by daemon" (lldb) 

    So, the functionality seems to be there, but the error messages are thrown still but not consistently.

    Also, I can only see the messages when building for a physical device (8+) but not in the Simulator for the same model,

  • I have the same issue with XCode Version 13.4 (13F17a). When will the fix be released as an update?

Add a Comment

I have a similar issue in Xcode 14.2. I see the message Failed to log access with error: access=<PATCCAccess 0x281ab0a00> accessor:<<PAApplication 0x281ac93b0 identifierType:auditToken identifier:{pid:12627, version:307689}>> ... but I seem to get access to what I'm requesting anyway.