2017-02-14 7 views
-1

Alamofireバージョン3.1.5をxCodeバージョン7.3で使用しています。私は私の多くのアプリで試してみました。しかし、私は結果が得られません。実行前にエラーは見られません。私のコードは次のようなものです:Alamofireを使用中に結果が得られません

var apiUrl : String 
var alamoFireManager:Manager! 
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration() 
init(apiUrl : String){ 
     self.apiUrl = apiUrl 
     configuration.timeoutIntervalForRequest = 30.0 
     alamoFireManager = Alamofire.Manager(configuration: configuration) 
    } 
print(apiUrl) 
alamoFireManager.request(.GET, apiUrl, encoding: .JSON).validate(contentType: ["application/json"]) .responseJSON { response in 
      print(response.result.value) 
      switch response.result{ 
      case .Success: 
       if let value = response.result.value{ 
        let json = JSON(value) 
        print (json) 
        callback.onResponse(value) // this is where my value is sent 
       } 
      case .Failure(let error): 
       print(error.localizedDescription) 
      } 
     } 

私はブレークポイントを使用してチェックし、アプリケーションはこの最後の中カッコ内のアラモファラインに直接到達します。

+0

を試し 'プリント(response.result.value)は'最終的に到達し得るのか? – luk2302

+0

いいえ、そうではありません。 alamofireManagerの行から直接末尾の括弧に移動します –

答えて

0

私は問題はあなたがresume()に電話していないと思います。 Alamofireドキュメントから

所有マネージャはstartRequestsImmediatelyが trueに設定されていない場合は、要求が開始するために履歴書を()を呼び出す必要があります。

この

alamoFireManager.request(.GET, apiUrl, encoding: .json).validate(contentType: ["application/json"]).resume().responseJSON { response in 
     print(response.result.value) 
     switch response.result{ 
     case .Success: 
      if let value = response.result.value{ 
       let json = JSON(value) 
       print (json) 
       callback.onResponse(value) // this is where my value is sent 
      } 
     case .Failure(let error): 
      print(error.localizedDescription) 
     } 
    } 
+0

再開の呼び出し時に "tuple type '()のメンバーにresponseJSONのメンバーがありません"というエラーを再度表示します。有難う御座います –

関連する問題