2016-10-18 3 views
1

私はAlamofireをcocoapodsで追加しました。私はzipファイル(約50Mb)をダウンロードする方法を持っています。MacOSでAlamofireをダウンロードしてください。うまく見える、進捗状況は機能していますが、ファイルはありませんか?

ダウンロード中はすべて完璧に見えます。私はアクティビティモニターで、私のアプリ用に50Mbがダウンロードされているのを見ることができます。プログレスバーが横になっているのがわかります。しかし、私はファイルを見つけることはできません。

現在、私は現在のディレクトリを使用するように設定していますが、他の場合に備えて試してみました。私はドライブ全体を変更して検索し、何も見つけられませんでした。

ここに私のコードです。

func downloadAndInstall(){ 
     log.info("Downloading and Installing.....") 
     displayToUser(content: "Downloading and Installing.....") 

     let urlString = updatePackageURL //(This is http://xxxx.com/xxxxpackage.zip) 
     let fileManager = FileManager.default 
     currentDir = fileManager.currentDirectoryPath 
     let fileURL: URL = URL(string: currentDir + "/package.zip")! 
     let destination: DownloadRequest.DownloadFileDestination = { _, _ in (fileURL, []) } 
     log.info("FILEURL: \(fileURL)") 
     var progressValues: [Double] = [] 
     var response: DefaultDownloadResponse? 

     Alamofire.download(urlString, to: destination) 
      .downloadProgress { progress in 
       progressValues.append(progress.fractionCompleted) 
       log.info("Latest Progress Value: \(progress.fractionCompleted)") 
       self.progBar.doubleValue = progress.fractionCompleted 
      } 
      .response { resp in 
       response = resp 
       if progressValues.last != 1.0 { 
        //backout of the process, something went wrong 
        log.debug("Something went wrong downloading the file. Close and try again.") 
        self.displayToUser(content: "Something went wrong downloading the file. Close and try again.") 
        self.exitpoorly() 
       } 
       else{ 
        log.info("Download Finished") 
        self.displayToUser(content: "Download Finished") 
        self.extractpackage() 
       } 
     } 

     var previousProgress: Double = progressValues.first ?? 0.0 

     for progress in progressValues { 
      previousProgress = progress 
     } 

     if let lastProgressValue = progressValues.last { 
      log.info("Current Download Value: \(lastProgressValue, 1.0)") 
     } else { 
      //Fail 
     } 
    } 

答えて

0

私は例えば、エラーがないかチェックすることをお勧めしたい。:

Alamofire.download(urlString, to: destination) 
    .downloadProgress { progress in 
     ... 
    } 
    .response { response in 
     guard response.error == nil else { 
      //backout of the process, something went wrong 
      log.debug("Something went wrong downloading the file. Close and try again.") 
      log.debug(response.error!.localizedDescription) 
      ... 
      self.exitpoorly() 
      return 
     } 

     log.info("Download Finished") 
     ... 
} 

をたぶんアプリはサンドボックス化された、または、おそらくあなたは、そのフォルダのアクセス権を持っていません。エラーを見ずに言うのは難しいです。

+1

私はファイルのURLに問題があります...私が見たいものを正確に伝えました。ありがとう! – Redracer68

関連する問題