Blame view

App/utils/NetWorkUtils.swift 2.57 KB
defd9642e   Trịnh Văn Quân   version 1.2
1
2
3
4
5
6
7
8
  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.
fbd62afcf   Trịnh Văn Quân   version 1.2.2
9
10
11
12
13
      import Alamofire
      let parameters: Parameters = [
                  "idWorker": getIDWork(),
                  "signboard": signboard == 1,
          ]
defd9642e   Trịnh Văn Quân   version 1.2
14
15
      */
      public static func excutePostTypeRawJSONEncoding(parameters: Parameters, url: String, isShowProgress: Bool? = nil, vc: UIViewController? = nil,
fbd62afcf   Trịnh Văn Quân   version 1.2.2
16
                                                       responseStringParam: (@escaping (DataResponse<String>) -> Void)) {
defd9642e   Trịnh Văn Quân   version 1.2
17
18
19
20
21
22
23
24
25
          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,
fbd62afcf   Trịnh Văn Quân   version 1.2.2
26
                                                            responseStringParam: @escaping (DataResponse<String>) -> Void) {
defd9642e   Trịnh Văn Quân   version 1.2
27
28
29
30
          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,
fbd62afcf   Trịnh Văn Quân   version 1.2.2
31
                                    responseStringParam: @escaping (DataResponse<String>) -> Void) {
defd9642e   Trịnh Văn Quân   version 1.2
32
33
34
          if isShowProgress == true {
              vc?.showWaitOverlay(isBlockTouch: true)
          }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
35
36
          println("excutePost: " + url)
          println(parameters)
defd9642e   Trịnh Văn Quân   version 1.2
37
38
          Alamofire.request(url, method: .post, parameters: parameters, encoding: encoding)
                  .responseString { response in
fbd62afcf   Trịnh Văn Quân   version 1.2.2
39
                      println(response.value)
defd9642e   Trịnh Văn Quân   version 1.2
40
41
42
43
44
45
46
                      if isShowProgress == true {
                          vc?.removeAllOverlays()
                      }
                      responseStringParam(response)
                  }
      }
  }