Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从iPhone设备上传视频失败,但可以在模拟器上正常工作错误:';无法读取文件';_Ios_Iphone_Swift_Aws Sdk Ios - Fatal编程技术网

Ios 从iPhone设备上传视频失败,但可以在模拟器上正常工作错误:';无法读取文件';

Ios 从iPhone设备上传视频失败,但可以在模拟器上正常工作错误:';无法读取文件';,ios,iphone,swift,aws-sdk-ios,Ios,Iphone,Swift,Aws Sdk Ios,我正在尝试从iPhone设备上传视频,如下所示: var uploadTask = self.session?.uploadTaskWithRequest(request, fromFile:NSURL(string: assetFilePath.path)!) 这段代码在模拟器上运行,并提供了一个会话任务对象,我可以恢复它。但它在iPhone设备上不起作用 它失败的原因是: 2015-05-19 18:36:44.718 myApp[327:24703] *** Terminating ap

我正在尝试从iPhone设备上传视频,如下所示:

var uploadTask = self.session?.uploadTaskWithRequest(request, fromFile:NSURL(string: assetFilePath.path)!)
这段代码在模拟器上运行,并提供了一个会话任务对象,我可以恢复它。但它在iPhone设备上不起作用

它失败的原因是:

2015-05-19 18:36:44.718 myApp[327:24703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot read file at file:///var/mobile/Media/DCIM/100APPLE/IMG_0144.mp4'
我试图检查视频文件是否具有读取权限,但在iPhone上返回false:

fileManager.fileExistsAtPath(asset.path)  // returns false
以前有人遇到过这种情况,还是我做错了什么

我用来获取文件路径的代码是:

    let options = PHFetchOptions()
    options.sortDescriptors = [
        NSSortDescriptor(key: "creationDate", ascending: true)
    ]
    currentVideofetch = PHAsset.fetchAssetsWithMediaType(.Video, options: options)
    let asset = self.currentVideofetch.objectAtIndex(indexPath.row) as? PHAsset  
    var assetLength:NSNumber!
    var assetFilePath:NSString!

    if let checkdAsset = asset {
        PHImageManager.defaultManager().requestImageDataForAsset(checkdAsset,options: nil) {
            imageData,dataUTI,orientation,info in

            assetLength = imageData.length as NSNumber
            let assetFilePathUrl  = info["PHImageFileURLKey"] as? NSURL
            assetFilePath = assetFilePathUrl!.absoluteString! 
            println("Assets FilePath \(assetFilePath)") // returns file:///var/mobile/Media/DCIM/100APPLE/IMG_0144.mp4
        }
    }

在和洛特搞砸之后。这是iOS中典型的权限问题。不幸的是,我没有得到任何直接的答案。我们必须将文件复制到我的应用程序的本地目录。从那以后,一切都变得很有魅力。
但对于大文件,我会在后台任务中发送复制文件逻辑。

您是否尝试使用requestAVAssetForVideo而不是requestImageDataForAsset?