返回的accessToken
为null
。
这是我的代码:
func commonNetworkCallWithHeader(completion:@escaping (String) -> Void)->String {
var accessToken = "";
Alamofire.request(apiUrl, method: .post, parameters: parameters, headers: headers).responseString { (response) in
if(response.result.isSuccess) {
if let jsonResponse = response.result.value {
if let jsonTrial = jsonResponse.data(using: .utf8, allowLossyConversion: false) {
let jsonConvert = JSON(data: jsonTrial)
accessToken = jsonConvert["access_token"].stringValue
completion(accessToken)
print("method:" + accessToken)
}
}
}
}
return accessToken
}