And*_*ewS 2 permissions firebase uicollectionview swift swift3
所以我通过自定义 UICollectionView 访问用户的视频和照片,我的问题是,当我尝试通过手机上传视频到 firebase 时,我收到此错误:
\n\n2017-09-03 13:09:20.884509-0400 Project[5797:2021536] Cannot get file size: Error Domain=NSCocoaErrorDomain Code=257 "The file \xe2\x80\x9cIMG_3476.MP4\xe2\x80\x9d couldn\xe2\x80\x99t be opened because you don\xe2\x80\x99t 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"}}\n /var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4\n2017-09-03 13:09:21.261767-0400 Project[5797:2021536] Body file is unreachable: /var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4\n Error Domain=NSCocoaErrorDomain Code=257 "The file \xe2\x80\x9cIMG_3476.MP4\xe2\x80\x9d couldn\xe2\x80\x99t be opened because you don\xe2\x80\x99t 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"}}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我加载文件的地方
\n\nstruct Media {\n var image:UIImage?\n var videoURL:NSURL?\n}\n\nvar mediaArray = [Media]()\n\nfunc grabPhotos(){\n let imgManager = PHImageManager.default()\n\n let requestOptions = PHImageRequestOptions()\n requestOptions.isSynchronous = true\n requestOptions.deliveryMode = .highQualityFormat\n\n let fetchOptions = PHFetchOptions()\n fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]\n if let fetchResult : PHFetchResult = PHAsset.fetchAssets(with: .video, options: fetchOptions) {\n\n\n if fetchResult.count > 0 {\n for i in 0..<fetchResult.count{\n var mediaItem = Media()\n //Used for fetch Image//\n imgManager.requestImage(for: fetchResult.object(at: i) as PHAsset , targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFit, options: requestOptions, resultHandler: {\n image, error in\n let imageOfVideo = image! as UIImage\n mediaItem.image = imageOfVideo;\n //Used for fetch Video//\n imgManager.requestAVAsset(forVideo: fetchResult.object(at: i) as PHAsset, options: PHVideoRequestOptions(), resultHandler: {(avAsset, audioMix, info) -> Void in\n if let asset = avAsset as? AVURLAsset {\n let videoData = NSURL(string: "\\(asset.url)")\n let duration : CMTime = asset.duration\n let durationInSecond = CMTimeGetSeconds(duration)\n print(durationInSecond)\n mediaItem.videoURL = videoData!\n self.mediaArray.append(mediaItem)\n print(self.mediaArray.count)\n\n\n }\n\n })\n })\n }\n\n }\n else{\n //showAllertToImportImage()//A function to show alert\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我认为这与我上传视频的时间无关,因为我可以录制视频并从手机上传,但不能从手机本身上传;我只是将 url 转移到 nextVC,如下所示:
\n\nlet videoVC = PrepareVideoVC()\n videoVC.url = outputFileURL as URL!\n self.navigationController?.pushViewController(videoVC, animated: false)\nRun Code Online (Sandbox Code Playgroud)\n\n我调查了这个文件 \xe2\x80\x9c \xe2\x80\x9d 无法\xe2\x80\x99t 被打开,因为你没有\xe2\x80\x99t 有权限查看它,但无法真正弄清楚如何实现它
\n\n我还遇到了/sf/answers/2906201581/但我再次尝试实现它,但无法让它不给我错误
\n\n另外模拟器可以上传,手机不行
\n\n它正在尝试从此目录获取文件:
\n\nNSFilePath=/var/mobile/Media/DCIM/\nRun Code Online (Sandbox Code Playgroud)\n
你可以试试
url.startAccessingSecurityScopedResource()
<...>
url.stopAccessingSecurityScopedResource()
Run Code Online (Sandbox Code Playgroud)