gpt4 book ai didi

ios - 无法检索文件,错误 : The file couldn’t be opened because you don’t have permission to view it

转载 作者:行者123 更新时间:2023-11-28 08:35:57 28 4
gpt4 key购买 nike

我正在使用的应用程序一直运行良好。我可以从库中选择一张图片并上传到 Firebase。但是,它突然不允许我从照片库上传文件。从模拟器上看,没有问题。只有在我的手机上,我才会收到该错误。

我收到的错误是

Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_8982.JPG” couldn’t be opened because you don’t have permission to view it." 
UserInfo={NSURL=file:///var/mobile/Media/DCIM/138APPLE/IMG_8982.JPG,
NSFilePath=/var/mobile/Media/DCIM/138APPLE/IMG_8982.JPG,
NSUnderlyingError=0x12ed877f0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

这很奇怪,因为我一直在这样做,但今天突然停止工作了。

这就是我的代码的样子。

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

// Clear data if picture is repicked

imageLocalURL = nil
imageData = nil

imageSelected = info[UIImagePickerControllerOriginalImage] as? UIImage

if info[UIImagePickerControllerReferenceURL] != nil {

// Image is selected from Photo Library
referenceURL = info[UIImagePickerControllerReferenceURL] as? NSURL

} else {

// Image is taken from camera
imageData = UIImageJPEGRepresentation(imageSelected!, 1.0)

}

transportImage.image = imageSelected
dismissViewControllerAnimated(true, completion: nil)

}


func saveDetails() {

if imageSelected != nil {

if referenceURL != nil {

// Image is from photo library

let assets = PHAsset.fetchAssetsWithALAssetURLs([referenceURL! as NSURL], options: nil)
let asset = assets.firstObject
let checkValidation = NSFileManager.defaultManager()
asset?.requestContentEditingInputWithOptions(nil, completionHandler: { (contentEditingInput, info) in
self.imageLocalURL = contentEditingInput?.fullSizeImageURL

// I did this to check if there is a local URL and if the file exist, but it returns false
print(self.imageLocalURL)
print(checkValidation.fileExistsAtPath("\(self.imageLocalURL)"))

self.uploadTask = storageRef.child(filePath).putFile(self.imageLocalURL!, metadata: nil) { (metadata, error) in
if let error = error {
print("Error uploading: \(error.description)")
return

}
}

} else if imageData != nil {

let imageLocalData = UIImageJPEGRepresentation(imageSelected!, 0.8)
let metadata = FIRStorageMetadata()
metadata.contentType = "image/jpeg"
uploadTask = storageRef.child(filePath).putData(imageLocalData!, metadata: metadata) { (metadata, error) in
if let error = error {
print("Error uploading: \(error)")
return
}

}

UIImageWriteToSavedPhotosAlbum(imageSelected!, nil, nil, nil)

}

如果图像是从相机拍摄的,则没有问题。如果图像取自照片库,我会收到该错误。

我四处搜索并尝试了 Option+Clean 构建。我去了 Projects->derived data-> delete 我检查了编译器是默认的。

谁能帮我解决这个问题?

最佳答案

我猜您一旦超出 didFinishPickingMediaWithInfo 的范围就会被拒绝访问。

也许您可以从中提取图像,而不是保留 URL?

UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];

编辑:

抱歉,没有注意到您使用的是 Swift,并且您已经拉取了图像。不过,我的建议仍然有效。保留图片而不是 URL,你应该没问题。

关于ios - 无法检索文件,错误 : The file couldn’t be opened because you don’t have permission to view it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37709850/

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