Note: Build on Xcode 6, swift1.2, swift2 All method are asynchronous.
With CocoaPods:
Use ~> "2.X.X" for swift 1.2 Use ~> "3.X.X" for swift 2
pod 'ApiNetWork'
CocoaPods requires iOS 8.0 or higher. If you're supporting iOS 7, or if you prefer, you can just drop ApiNetWork.swift to your project.
ApiNetwork.launchRequest("http://www.google.fr", completion:
{ (response) -> Void in
})
or
let a = ApiNetwork(stringURL: "your-url")
a.launchRequest(didReceived: nil) { (response) -> Void in
}
//yourUrl?user=jack&password=test
let n : ApiNetwork = ApiNetwork(stringURL: "yourUrl")
n.addParameterWithKey("user", "jack")
n.addParameterWithKey("password", "test")
let iv : UIImageView = UIImageView()
let a = ApiNetwork.launchRequestDownloading("your-url", didReceived: nil)
{ (response) -> Void in
if response.errors == nil {
if let data = response.getResponseData() {
iv.image = UIImage(data: data)
}
} else if response.didFailNotConnectedToInternet() == true {
println("not connection to internet")
}
}
let a = ApiNetwork(stringURL: "your-url")
a.setPathFileDownload("path-to-downlaod-file")
a.launchRequestDownloading(didReceived: nil) { (response) -> Void in
}
You can resume a download simple by re-launch the request. It's only work if you use setPathFileDownload
Call method stopDownloading()
By default, method is set to .GET but can change to .GET .POST .DELETE .PUT .PATCH .HEAD
let a = ApiNetwork(stringURL: "your-url")
a.setMethod(.POST)
a.launchRequest { (response) -> Void in
// DO YOU WANT
}
For each request, the response will return a ApiNetworkResponse class.
Use this method to get your result of request
getResponseString()
getResponseData()
getResponseDictionary()
status_code
errors
header
URL
mime_type
expectLengthDownloading
totalLengthDownloaded
Ask me on hangout, +BillaNorbert