当我尝试加载已保存到设备的本地文件时,它会抛出"不支持的网址":
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 }