使用dataTaskWithURL加载本地文件会抛出不支持的URL - Swift

时间:2016-03-08 00:40:48

标签: ios swift file

当我尝试加载已保存到设备的本地文件时,它会抛出"不支持的网址":

let filePath = getDocumentsDirectory().stringByAppendingPathComponent(myFileName)

NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: filePath)!) { (data, response, error) in
            completion(data: data, error: error)
            }.resume()



class func getDocumentsDirectory() -> NSString {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentsDirectory = paths[0]
    return documentsDirectory
}

但是当我使用相同的filePath时,返回true:

let checkValidation = NSFileManager.defaultManager()
        if (checkValidation.fileExistsAtPath(filePath)){ return true }

0 个答案:

没有答案