-1
我有這段代碼在我的應用程序中用於登錄。它曾經在swift 1中工作,但是當我將整個應用程序迅速啓動時,它停止工作。注:該代碼編譯沒有錯誤,問題是,它不執行請求在AFNetworking中使用Swift 2進行POST
@IBAction func signIn(sender: AnyObject) {
let body = NetUtils.buildLoginRequestBody(email: emailField.text!, password: passwordField.text!);
let manager = AFHTTPRequestOperationManager();
manager.requestSerializer = AFJSONRequestSerializer() as AFHTTPRequestSerializer;
manager.responseSerializer = AFJSONResponseSerializer();
barActivityIndicator.startAnimating();
setViewsEnabled(false);
manager.POST(LoginURL, parameters: body,
success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
NSLog("success code: %d", operation.response!.statusCode);
print(JSON(responseObject))
self.processUserData(JSON(responseObject));
self.barActivityIndicator.stopAnimating();
self.setViewsEnabled(true);
},
failure: { (operation: AFHTTPRequestOperation?, error: NSError!) in
NSLog("error: %@", error.localizedDescription);
self.barActivityIndicator.stopAnimating();
self.setViewsEnabled(true);
self.alert.show();
}
);
}
檢查你的'signIn(sender:AnyObject)'和UI Element第一個 – Breek
之間的鏈接已經檢查,它的罰款 –