立即使用Alamo火进行封锁

时间:2019-10-21 10:53:28

标签: ios swift callback closures block

我正在为Alamo的一些消防电话编写一个小包装,并遇到一些关闭问题,该关闭在Alamo的消防响应之前被调用

var manager = Alamofire.SessionManager.default {
   didSet {
      self.manager.session.configuration.timeoutIntervalForRequest = 30
   }
}

//Create my function signature
func sendInformation(parameters: [String: Any], completion: @escaping (_ success: Bool, _ error: String?) -> Void) {
   //helper for creating params / headers etc 
   let request = HelperRequest().submitNewPassport(parameters: parameters)

   manager.request(request.requestURL,
      method: request.method,
      parameters: request.parameters,
      encoding: request.encoding,
      headers: request.headers).responseJSON { (response) in
         print("** Updated called")
         if response.result.isSuccess {
            //show success
            completion(true, nil)
            return
         } else {
            //show error
            completion(false, error.localizedDescription)
            return
         }
completion(false, nil)

但是,当调用此方法时,我会在发出请求和随后的正确回调之前立即获得失败完成

sendInformation(parameters: params,  { (success, error) -> Void in
   if success {
      print("** success")
   } else {
      print("** error ")
   }

日志如下

** error 
** Updated called
** Success

0 个答案:

没有答案