Post

Replies

Boosts

Views

Activity

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
3
0
6.1k
Jun ’23
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
Replies
3
Boosts
0
Views
6.1k
Activity
Jun ’23