Blame view
App/utils/NetWorkUtils.swift
2.31 KB
defd9642e
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import GeneralUtils import Foundation import Alamofire extension NetWorkUtils { /** The JSONEncoding type creates a JSON representation of the parameters object, which is set as the HTTP body of the request. The Content-Type HTTP header field of an encoded request is set to application/json. */ public static func excutePostTypeRawJSONEncoding(parameters: Parameters, url: String, isShowProgress: Bool? = nil, vc: UIViewController? = nil, responseStringParam: @escaping (DataResponse<String>) -> Void) { NetWorkUtils.excutePost(parameters: parameters, url: url, isShowProgress: isShowProgress, vc: vc, encoding: JSONEncoding.default, responseStringParam: responseStringParam) } public static func excutePostTypeFormURLEncoded(parameters: Parameters, url: String, isShowProgress: Bool? = nil, vc: UIViewController? = nil, responseStringParam: @escaping (DataResponse<String>) -> Void) { NetWorkUtils.excutePost(parameters: parameters, url: url, isShowProgress: isShowProgress, vc: vc, encoding: URLEncoding.default, responseStringParam: responseStringParam) } public static func excutePostTypePropertyListEncoding(parameters: Parameters, url: String, isShowProgress: Bool? = nil, vc: UIViewController? = nil, responseStringParam: @escaping (DataResponse<String>) -> Void) { NetWorkUtils.excutePost(parameters: parameters, url: url, isShowProgress: isShowProgress, vc: vc, encoding: PropertyListEncoding.default, responseStringParam: responseStringParam) } public static func excutePost(parameters: Parameters, url: String, isShowProgress: Bool? = nil, vc: UIViewController? = nil, encoding: ParameterEncoding, responseStringParam: @escaping (DataResponse<String>) -> Void) { if isShowProgress == true { vc?.showWaitOverlay(isBlockTouch: true) } Alamofire.request(url, method: .post, parameters: parameters, encoding: encoding) .responseString { response in if isShowProgress == true { vc?.removeAllOverlays() } responseStringParam(response) } } } |