gpt4 book ai didi

ios - PHPickerViewController 通过 PHAsset 加载视频

转载 作者:行者123 更新时间:2023-12-04 01:13:07 62 4
gpt4 key购买 nike

PHPickerViewController 允许访问照片库 Assets 的副本以及在结果中返回 PHAssets。为了获得 PHAssets 而不是文件副本,我这样做:

        let photolibrary = PHPhotoLibrary.shared()
var configuration = PHPickerConfiguration(photoLibrary: photolibrary)
configuration.filter = .videos
configuration.selectionLimit = 0

let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
self.present(picker, animated: true, completion: nil)
进而,
 //MARK:- PHPickerViewController delegate

@available(iOS 14, *)
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {

picker.dismiss(animated: true) {
let identifiers:[String] = results.compactMap(\.assetIdentifier)
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: nil)

NSLog("\(identifiers), \(fetchResult)")
}

}
但问题是一旦照片选择器被关闭,它会提示访问照片库,这令人困惑,并且由于用户无论如何都隐式地授予了对 PHPickerViewController 中选定 Assets 的访问权限,PHPhotoLibrary 应该直接加载这些 Assets 。有没有办法避免照片库权限?

最佳答案

Is there anyway to avoid the Photo library permission?


是的,有点:
  • 更改 PHPickerConfiguration(photoLibrary: photolibrary)PHPickerConfiguration()
  • 不要使用 assetIdentifier返回照片库(无论如何都是nil)

  • 在这种情况下,用户可以为您提供图像数据,仅此而已。选择器处于进程外,并没有真正遇到来自库本身的数据,只是用户明确选择的一个图像。
    但是,如果您的目标确实是返回照片库并获取 PHAsset,那么您必须获得许可,因为您现在确实试图在您的应用程序中探查幕后的照片库。
    当我的应用程序依赖于 PHAsset 信息时,我所做的是在展示选择器之前请求照片库许可(如果需要),如果我无法获得许可,我不会展示选择器。所以,用户点击一个按钮,我发现我们没有权限,我请求权限,我们得到了它(假设),然后我展示了选择器(做异步舞蹈,因为权限异步到达)。看起来很棒。
    顺便说一句,这对于 UIImagePickerController 也是如此。

    关于ios - PHPickerViewController 通过 PHAsset 加载视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64223430/

    62 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com