根据您的描述,您遇到的问题可能是由于禁用了相册联网权限导致的。iCloud 照片同步优化会将照片存储在云端,只有在需要访问时才会下载到设备上。如果您禁用了相册联网权限,即使在设备上存在 iCloud 照片,也无法通过 PHPickerViewController 选择照片。

要解决这个问题,您可以按照以下步骤操作:

  1. 打开设备的设置应用程序。
  2. 滚动并找到您的应用程序,然后点击进入。
  3. 点击'照片'选项。
  4. 打开'联网照片'开关,允许应用程序访问相册联网权限。
  5. 重新打开您的应用程序,尝试使用 PHPickerViewController 选择照片。

通过打开相册联网权限,您的应用程序将能够访问 iCloud 照片,并在 PHPickerViewController 中显示可用的照片。

请注意,用户可能会对应用程序访问相册联网权限进行授权,并且在应用程序首次访问时可能会提示用户授权。在您的应用程序中,您可以使用 PHPhotoLibrary 类来请求相册联网权限,并在用户授权后再使用 PHPickerViewController 选择照片。

import PhotosUI

class YourViewController: UIViewController {
    // ...
    
    func requestPhotoLibraryAuthorization() {
        PHPhotoLibrary.requestAuthorization { status in
            DispatchQueue.main.async {
                if status == .authorized {
                    self.showPhotoPicker()
                } else {
                    // 处理用户未授权的情况
                }
            }
        }
    }
    
    func showPhotoPicker() {
        let picker = PHPickerViewController(configuration: PHPickerConfiguration())
        picker.delegate = self
        present(picker, animated: true, completion: nil)
    }
    
    // ...
}

extension YourViewController: PHPickerViewControllerDelegate {
    func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
        // 处理选择的照片
        picker.dismiss(animated: true, completion: nil)
    }
}

通过使用 PHPhotoLibrary.requestAuthorization 方法,您可以在应用程序中请求相册联网权限,并在用户授权后使用 PHPickerViewController 选择照片。

希望这些信息能帮助到您解决问题。如果您有任何进一步的疑问,请随时提问。

iPhone 存储空间优化:禁用相册联网权限导致 PHPickerViewController 无法选择照片的解决方法

原文地址: https://www.cveoy.top/t/topic/fp9H 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录