I have a naive implementation of the new PHPicker in SwiftUI (code below). When running on a separate device (iPhone 6s, iOS 14.0), I am able to load some images, but not others.
The images that do not load seem to encounter a permissions error:
I'm a little confused because I thought a core value proposition of the new PHPicker was that it automatically allowed access to selected photos.
When I try selecting an image using Simulator, I just get the second error (does not exist), but not the first.
I'm also noticing that the main photos grid does not seem to automatically update with new photos, even though the "Recent" album does. I have to force quit and restart the app to see the latest photos appear, though I have not been able to load any of them due to the issue described above.
The images that do not load seem to encounter a permissions error:
Code Block // [...] indicates redacted content for brevity [...] [default] [ERROR] Could not create a bookmark: NSError: Cocoa 257 "The file couldn’t be opened because you don’t have permission to view it." } [...] [claims] Upload preparation for claim [...] completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “[...].jpeg” couldn’t be opened because there is no such file." UserInfo={NSURL=[...]{Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
I'm a little confused because I thought a core value proposition of the new PHPicker was that it automatically allowed access to selected photos.
When I try selecting an image using Simulator, I just get the second error (does not exist), but not the first.
I'm also noticing that the main photos grid does not seem to automatically update with new photos, even though the "Recent" album does. I have to force quit and restart the app to see the latest photos appear, though I have not been able to load any of them due to the issue described above.
Code Block swift // // PhotoPicker.swift // NewParis // // Created by Yihwan Kim on 7/12/20. // import SwiftUI import UIKit import PhotosUI struct PhotoPicker: UIViewControllerRepresentable { @Binding var isPresented: Bool @Binding var selectedImage: Image? func makeUIViewController(context: Context) -> PHPickerViewController { var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared()) configuration.filter = .images let controller = PHPickerViewController(configuration: configuration) controller.delegate = context.coordinator return controller } func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { } func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: PHPickerViewControllerDelegate { private let parent: PhotoPicker init(_ parent: PhotoPicker) { self.parent = parent } func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { parent.isPresented = false if let itemProvider = results.first?.itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) { itemProvider.loadObject(ofClass: UIImage.self) { [weak self] uiImage, error in DispatchQueue.main.async { guard let self = self, let uiImage = uiImage as? UIImage else { return } self.parent.selectedImage = Image(uiImage: uiImage) } } } } } }