Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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 如何将Firebase存储中的PDF文件保存到应用程序文档中以备将来使用?_Ios_Swift_Pdf_Firebase_Firebase Storage - Fatal编程技术网

Ios 如何将Firebase存储中的PDF文件保存到应用程序文档中以备将来使用?

Ios 如何将Firebase存储中的PDF文件保存到应用程序文档中以备将来使用?,ios,swift,pdf,firebase,firebase-storage,Ios,Swift,Pdf,Firebase,Firebase Storage,我已将我的应用程序连接到Firebase存储,其中存在我的19ea PDF文件 我想下载这些文件并保存在本地以备将来使用 这些PDF文件将在UIWebView中使用,但可能需要及时更新。因此,我已使用Firebase数据库配置了版本控制系统,因此在更新存储中的文件时,我将能够推送更新的版本 那么,如何在本地保存这些文件?(如:user/myapp/Documents/PDF等文件夹) 另外,我如何检查该文件夹是否包含任何文档,以及如何在下载新文件之前删除它们 这是我到目前为止得到的 我感谢所有的

我已将我的应用程序连接到Firebase存储,其中存在我的19ea PDF文件

我想下载这些文件并保存在本地以备将来使用

这些PDF文件将在UIWebView中使用,但可能需要及时更新。因此,我已使用Firebase数据库配置了版本控制系统,因此在更新存储中的文件时,我将能够推送更新的版本

那么,如何在本地保存这些文件?(如:user/myapp/Documents/PDF等文件夹)

另外,我如何检查该文件夹是否包含任何文档,以及如何在下载新文件之前删除它们

这是我到目前为止得到的

我感谢所有的帮助

// Firebase Storage Connection
static var refStorage:FIRStorageReference?
static var dataPDF = [NSData]()

func newDataDownload(){

// Compare Current Data Version with Online Data Version
if myFirebaseData.localDataVersion < myFirebaseData.onlineDataVersion {

    // Set Firebase Storage Reference
    myFirebaseData.refStorage = FIRStorage.storage().reference()

    for i in 1...myFirebaseData.onlineTotalPDFCount {


        // Create a reference to the file you want to download
        let pulledPDF = FIRStorage.storage().reference().child("/PDF/\(i).pdf")

        // Create local filesystem URL
        let localURL = URL(string: "myApp/Documents/PDF/\(i)")!

        pulledPDF.data(withMaxSize: myFirebaseData.maxPDFdownloadSize, completion: { (downPDF, err) in
            if err == nil {
                // Accessed the data
                myFirebaseData.dataPDF.append(downPDF! as NSData)
                print(myFirebaseData.dataPDF)


            } else {
                // If there is an error print it
                print(err.debugDescription)
            }
        })
    }
}

// If Data is successfully downloaded update Local Data Version
myFirebaseData.localDataVersion = myFirebaseData.onlineDataVersion
//Firebase存储连接
静态变量引用存储:FIRStorageReference?
静态变量dataPDF=[NSData]()
func newDataDownload(){
//将当前数据版本与联机数据版本进行比较
如果myFirebaseData.localDataVersion
使用
storageRef.write(toFile:completion:)
(),如:

请注意,由于应用程序沙盒要求,您只能向
/tmp
/Documents
写入数据(请参阅此操作如何失败的示例)

// Create a reference to the file you want to download
let pdfRef = storageRef.child("files/file.pdf")

// Create local filesystem URL
let localURL = URL(string: "path/to/local/file.pdf")!

// Download to the local filesystem
let downloadTask = pdfRef.write(toFile: localURL) { url, error in
  if let error = error {
    // Uh-oh, an error occurred!
  } else {
    // Local file URL for "path/to/local/file.pdf" is returned
  }
}