gpt4 book ai didi

ios - PHAssetResourceManager writeData 返回错误 1

转载 作者:行者123 更新时间:2023-12-01 19:38:40 34 4
gpt4 key购买 nike

我正在尝试分享 PHAssetResource与原始文件名。此方法将 Assets 资源保存到临时目录并从那里共享。自 iOS 13 以来,这一直出现错误:

let tempDirectory = NSTemporaryDirectory() as NSString
let partialPath = tempDirectory.appendingPathComponent(sentAssetResource.originalFilename)
let fileURL = URL(fileURLWithPath: partialPath)

let options = PHAssetResourceRequestOptions()
options.isNetworkAccessAllowed = true


PHAssetResourceManager.default().writeData(for: sentAssetResource, toFile: fileURL, options: options, completionHandler: { (error) in

if (error != nil) {

print (error?.localizedDescription)
return
}

DispatchQueue.main.async {
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)

activityViewController.completionWithItemsHandler = {
(activity, success, items, error) in

if FileManager.default.fileExists(atPath: fileURL.path) {
try? FileManager.default.removeItem(atPath: fileURL.path)
}
}

self.present(activityViewController, animated: true, completion: {


})
}
})

收到的错误是:
The operation couldn't be completed.
(PHPhotosErrorDomain error -1.)

这里有什么问题?

我不得不切换到 PHAssetResourceManager.default().requestData ,但是这个共享没有正确的文件名。

最佳答案

在我的测试中,该方法在 iOS 13.2 上运行良好。该方法可能会因数据库错误而失败(iOS 照片库是 CoreData 数据库,AssetResources 是单独的表)。您能否在模拟器以及所有测试设备上重现该问题?

关于ios - PHAssetResourceManager writeData 返回错误 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58673133/

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