I am attempting to upload a video from a custom UICollection that accesses the users videos. When I attempt to upload the URL to firebase, I get the following error:
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"}}
I am a little confused as to why this is occuring, b/c when I print out the url of the video I get:
file:///var/mobile/Media/DCIM/103APPLE/IMG_3002.MOV
&& my info.plist looks like this
Here is the upload code:
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!!!")
}
})
&& just in-case here is the where I am fetching the videos
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
}
}
}
This issue is on the mobile not the simulator