2016-09-28 19 views
0
func downloadProgress(bytesRead: Int64, totalBytesRead: Int64, 
    totalBytesExpectedToRead: Int64) { 
    let percent = Float(totalBytesRead)/Float(totalBytesExpectedToRead) 

    dispatch_async(dispatch_get_main_queue(), { 
     self.progress.setProgress(percent,animated:true) 
    }) 
    print("Progress:\(percent*100)%") 
} 

func downloadResponse(request: NSURLRequest?, response: NSHTTPURLResponse?, 
    data: NSData?, error:NSError?) { 
    if let error = error { 
     if error.code == NSURLErrorCancelled { 
      self.cancelledData = data 
     } else { 
      print("Failed to download file: \(response) \(error)") 
     } 
    } else { 
     print("Successfully downloaded file: \(response)") 
    } 
} 

@IBAction func continueBtnClick(sender: AnyObject) { 
    if let cancelledData = self.cancelledData { 
     self.downloadRequest = Alamofire.download(resumeData: cancelledData, 
      destination: destination) 

     self.downloadRequest.progress(downloadProgress) 

     self.downloadRequest.response(completionHandler: downloadResponse) 

     self.stopBtn.enabled = true 
     self.continueBtn.enabled = false 
    } 
} 

Alamofire 3.1ではコードが正常に機能しますが、Swift 3.0およびAlamofire 4.0にアップグレードした後は機能しません。4.0へのアップグレード後にAlamofireメソッドが機能しない

次の2本のラインは、 "そのような進歩FO memeber" と

  1. self.downloadRequest.progress(downloadProgress)
  2. self.downloadRequest.response(completionHandler "応答のそのような部材" エラーを示しません。ダウンロード応答)

どのようにこれらの2つの問題を解決できますか?

ありがとうございました。

答えて

0

あなたが参照している機能は、Alamofire 4.0で変更されています。 "no members"エラーの理由は、関数呼び出しが変更されたためです。

Alamofire.download("https://httpbin.org/image/png") 
.downloadProgress { progress in 
    print("Download Progress: \(progress.fractionCompleted)") 
} 
.responseData { response in 
    if let data = response.result.value { 
    } 
} 

新機能のXcode(私もなく.DownloadとAlamofire 4.0を使用)によると:

downloadRequest.downloadProgress(closure: Request.ProgressHandler) 
downloadRequest.responseData(completionHandler: (DownloadResponse<Data>) -> Void) 
新しいドキュメントによれば、これはあなたが(おそらく)作るべきであることを呼び出しです

出典:Alamofire documentation for download progress

+0

ありがとうございます。できます。 – jdleung

+0

@jdleung恐ろしい!私は助けることができてうれしいです – tech4242

関連する問題