我有一个方法来下载一个MP3文件并保存它,该方法工作正常,百分比工作(sorta)

时间:2015-02-21 07:57:58

标签: ios iphone xcode swift mp3

下载mp3文件的方法有效,打印出的百分比也有效,但我想能够更改标签,我不会工作所有发生的是文件下载,同时打印出下载的百分比但不是当试图改变标签时。我究竟做错了什么?

func download_Songs(){
    var request = HTTPTask()
    let downloadTask = request.download(urlText, parameters: nil, progress: {(complete: Double) in
           var a:String = String(format: "%f", complete)
        self.PlaySong.titleLabel?.text = a
        println("percent complete: \(a)")
        }, success: {(response: HTTPResponse) in
            println("download finished!")
            if response.responseObject != nil {
                //we MUST copy the file from its temp location to a permanent location.
                if let url = response.responseObject as? NSURL {
                    if let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as? String {
                        if let fileName = response.suggestedFilename {
                            if let newPath = NSURL(fileURLWithPath: "\(path)/\(fileName)") {
                                let fileManager = NSFileManager.defaultManager()
                                fileManager.removeItemAtURL(newPath, error: nil)
                                fileManager.moveItemAtURL(url, toURL: newPath, error:nil)
                            }
                        }
                    }
                }
            }

        } ,failure: {(error: NSError, response: HTTPResponse?) in
            println("failure")
    })
}

Link to HTTPSwift (used for the download_Songs function)

1 个答案:

答案 0 :(得分:0)

NSURLConnectionDataDelegate是您应该寻找的