我尝试使用Firebase在swift4中检索pdf文档,我收到错误请检查下面的代码。
let storage = Storage.storage()
let storageRef = storage.reference()
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
print("Jun18-2018:\(documentsDirectory)")
var pdfRef = storageRef.child("pdfs/Hybris.pdf")
_ = pdfRef.putData(data, metadata: nil, completion: { (metadata,error ) in
guard let metadata = metadata else{
print(error)
return
}
let downloadURL = metadata.downloadURL()!
print(downloadURL)
guard let url = URL(string: paths[0]) else{return}
let downloadTask = storageRef.write(toFile: url)
{ url, error in
if let error = error {
print("err###########")
} else {
print("pdf downloaded...........")
}
}
downloadTask.observe(.resume) { snapshot in
print("downloaded ... resume")
}
downloadTask.observe(.pause) { snapshot in
print("downloaded ... paused")
}
downloadTask.observe(.progress) { snapshot in
let percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount)
/ Double(snapshot.progress!.totalUnitCount)
print("downloaded ... progress")
}
downloadTask.observe(.success) { snapshot in
print("downloaded ... successfully")
}
})
错误: "无法打开文件,因为不支持指定的URL类型。" 由于状态403而放弃下载 下载...进度 犯错###########