Guest User

Untitled

a guest
Dec 26th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. static func Login(username:String, password:String, completion: @escaping (_ success: Bool, _ response: DataResponse<Data?>?) -> ()) {
  2.  
  3. var response:DataResponse<Data?>?
  4.  
  5. AF.request("https://httpbin.org/basic-auth/(username)/(password)")
  6. .authenticate(username: username, password: password)
  7. .response { resp in
  8. response = resp
  9. completion(true,response)
  10. }
  11.  
  12. if(response?.response?.statusCode == 200)
  13. {
  14. completion(true, response)
  15. }
  16. else {
  17. completion(false, nil)
  18. }
  19. }
  20.  
  21. code from action outlet
  22. @IBAction func loginAction(sender: UIButton)
  23. {
  24. AutheManager.Login(username: newAccountName, password: newPassword) { (success, response) in
  25. if (success == true)
  26. {
  27. // rest of code
  28. }
  29. else
  30. {
  31.  
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment