ZKAlamofire
将 Alamofire、ZKProgressHUD、SwiftyJSON、ZKStatusBarNotification 封装,简化网络请求代码
近期更新
增加 setDefaultParameters 方法,用于设置所有请求默认参数,此默认参数会追加到请求参数中
实现功能
- 网络环境监控
- post、get
- HUD 方式 post、get
- 设置全局 header
- 设置默认参数
运行环境
- iOS 8.0 +
- Xcode 8 +
- Swift 4.0 +
安装
CocoaPods
你可以使用 CocoaPods 安装 ZKAlamofire
,在你的 Podfile
中添加:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'ZKAlamofire'
end
快速使用
ZKAlamofireRequestSuccess 中的 json 参数为 SwiftyJSON;在调用 get、getWithShowHUD、post、postWithShowHUD 中的参数大多数可以不填写,如果不需要设置此参数则可以删除此参数或者传 nil
ZKAlamofire
导入 import ZKAlamofire
网络监控
ZKAlamofire.startNetworkMonitoring()
打开网络监控之后,在使用 ZKAlamofire 请求时如果没有网络连接,会提示如下图
Get 请求
不显示加载
ZKAlamofire.get("url", success: (json) in
// 回调代码
}
显示加载
ZKAlamofire.getWithShowHUD("url", success: (json) in
// 回调代码
}
Post 请求
不显示加载
ZKAlamofire.post("url", parameters: nil, success: (json) in
// 回调代码
}
显示加载
ZKAlamofire.postWithShowHUD("url", parameters: nil, success: (json) in
// 回调代码
}
设置全局 Header
ZKAlamofire.setGlobalHeaders(["key": "value"])
设置默认参数
ZKAlamofire.setDefaultParameters(["key": "value"])
自定义 HUD 样式
自定义需要引用 ZKProgressHUD ,之后设置其样式即可