gpt4 book ai didi

swift - 错误域=NSCocoaErrorDomain 代码=257 无法打开 fil ""- Firebase

转载 作者:可可西里 更新时间:2023-11-01 02:01:26 24 4
gpt4 key购买 nike

所以我通过自定义 UICollectionView 访问用户的视频和照片,我的问题是当我尝试通过手机将视频上传到 firebase 时,出现此错误:

2017-09-03 13:09:20.884509-0400 Project[5797:2021536] Cannot get file size: Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_3476.MP4” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSFilePath=/var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSUnderlyingError=0x17064f450 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
/var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4
2017-09-03 13:09:21.261767-0400 Project[5797:2021536] Body file is unreachable: /var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4
Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_3476.MP4” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSFilePath=/var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSUnderlyingError=0x170651b20 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

这里是我加载文件的地方

struct Media {
var image:UIImage?
var videoURL:NSURL?
}

var mediaArray = [Media]()

func grabPhotos(){
let imgManager = PHImageManager.default()

let requestOptions = PHImageRequestOptions()
requestOptions.isSynchronous = true
requestOptions.deliveryMode = .highQualityFormat

let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
if let fetchResult : PHFetchResult = PHAsset.fetchAssets(with: .video, options: fetchOptions) {


if fetchResult.count > 0 {
for i in 0..<fetchResult.count{
var mediaItem = Media()
//Used for fetch Image//
imgManager.requestImage(for: fetchResult.object(at: i) as PHAsset , targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFit, options: requestOptions, resultHandler: {
image, error in
let imageOfVideo = image! as UIImage
mediaItem.image = imageOfVideo;
//Used for fetch Video//
imgManager.requestAVAsset(forVideo: fetchResult.object(at: i) as PHAsset, options: PHVideoRequestOptions(), resultHandler: {(avAsset, audioMix, info) -> Void in
if let asset = avAsset as? AVURLAsset {
let videoData = NSURL(string: "\(asset.url)")
let duration : CMTime = asset.duration
let durationInSecond = CMTimeGetSeconds(duration)
print(durationInSecond)
mediaItem.videoURL = videoData!
self.mediaArray.append(mediaItem)
print(self.mediaArray.count)


}

})
})
}

}
else{
//showAllertToImportImage()//A function to show alert
}
}
}

我认为这与我上传视频无关,因为我可以录制视频并从手机上传,而不是从手机本身上传;我只是像这样将 url 转移到 nextVC:

let videoVC = PrepareVideoVC()
videoVC.url = outputFileURL as URL!
self.navigationController?.pushViewController(videoVC, animated: false)

我调查了这个The file “ ” couldn’t be opened because you don’t have permission to view it但无法真正弄清楚如何实现它

我也遇到了https://stackoverflow.com/a/41517165/7823620但我又一次尝试实现它,但无法让它不给我错误

我也可以从模拟器上传,但不能从手机上传

它正在尝试从此目录中获取文件:

NSFilePath=/var/mobile/Media/DCIM/

最佳答案

你可以试试

url.startAccessingSecurityScopedResource()
<...>
url.stopAccessingSecurityScopedResource()

关于swift - 错误域=NSCocoaErrorDomain 代码=257 无法打开 fil ""- Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46025998/

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