2016-05-31 19 views
0

我想知道如何验证api调用的swift到我使用Active Directory验证用户的自定义服务。目前我的应用程序存储一个整数值,我想将其发布到服务。如何在swift中验证iOS应用程序

let thing = Int(emailTextField.text!) 
// POST method goes here ... 

回答

0

我只是认证我的应用程序这段代码。

if(isValidEmail && isValidPassword){ 
     print("sending to server for verification") 
     let params = ["user" : ["email" : "\(email!)", "password" : "\(password!)"]] 
     let url: String = "http://localhost:3000/users/sign_in" 
     Alamofire.request(.POST, url, parameters: params, encoding: .JSON, headers: nil).validate().responseJSON{ 
      response in 
      switch response.result{ 
      case .Success: 
       if let value = response.result.value{ 
        let jsn = JSON(value) 
        print("jsn: \(jsn)") 
        let authentication_token = jsn["authentication_token"] 
        if(authentication_token != nil){ 
         let vc = self.storyboard?.instantiateViewControllerWithIdentifier("dasboardViewController") as! DashBoardController 
         self.presentViewController(vc, animated: true, completion: nil) 
        } 
       } 
       break 
      case .Failure: 
       break 
      } 
     } 
    } 

确保Alamofire已导入。我在后端有rails服务器,并在localhost中测试过。此外,身份验证是使用电子邮件和密码,而不是数字完成的,并返回包含authentication_token字段的json。

相关问题