TestsTested | ✗ |
LangLanguage | SwiftSwift |
许可证 | MIT |
Released上次发布 | 2015年9月 |
SPM支持 SPM | ✗ |
由 Norbert Billa 维护。
注意:基于 Xcode 6、swift1.2、swift2 构建,所有方法都是异步的。
使用 CocoaPods
对于 swift 1.2 使用 ~> “2.X.X”,对于 swift 2 使用 ~> “3.X.X”
pod 'ApiNetWork'
Cocoapods 需要 iOS 8.0 或更高版本。如果您支持 iOS 7,或者您希望如此,您只需将 ApiNetWork.swift 添加到您的项目中即可。
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
}
您可以简单重发请求来恢复下载。只有在使用 setPathFileDownload 时才有效。
调用 stopDownloading() 方法。
默认情况下,方法设置为 .GET,但可以更改为 .GET .POST .DELETE .PUT .PATCH .HEAD
let a = ApiNetwork(stringURL: "your-url")
a.setMethod(.POST)
a.launchRequest { (response) -> Void in
// DO YOU WANT
}
对于每个请求,响应将返回一个 ApiNetworkResponse 类。
使用此方法获取请求的结果。
getResponseString()
getResponseData()
getResponseDictionary()
status_code
errors
header
URL
mime_type
expectLengthDownloading
totalLengthDownloaded
在 hangout 上联系我,+BillaNorbert