为什么Alamofire返回值为null的访问令牌?

时间:2017-06-01 07:49:01

标签: swift3 alamofire

返回的accessTokennull

这是我的代码:

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
}

0 个答案:

没有答案