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