我正在尝试从访问用户视频的自定义UICollection上传视频。当我尝试将URL上传到firebase时,出现以下错误:
Body file is unreachable: /var/mobile/Media/DCIM/103APPLE/IMG_3002.MOV
Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_3002.MOV” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/103APPLE/IMG_3002.MOV, NSFilePath=/var/mobile/Media/DCIM/103APPLE/IMG_3002.MOV, NSUnderlyingError=0x17024b790 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
我有点困惑为什么会发生这种情况,当我打印出我得到的视频的网址时b / c:
file:///var/mobile/Media/DCIM/103APPLE/IMG_3002.MOV
以下是上传代码:
videosFolder.child("\(nsuid).mov").putFile(self.videoURLToUpload, metadata: nil, completion: { (metadata, error) in
if error != nil {
print("we Had an Error!: \(String(describing: error))")
} else {
print("we uploaded the video correctly!!!")
}
})
&安培;&安培;只是在这里是我提取视频的地方
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
}
}
}
此问题出现在手机而不是模拟器上