我想知道如何快速验证我制作的自定义服务的 api 调用,该服务使用事件目录对用户进行身份验证。目前我的应用程序存储一个整数值,我想将其发布到服务。
let thing = Int(emailTextField.text!)
// POST method goes here ...
最佳答案
我只是使用这段代码验证我的应用程序。
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 服务器,并且在本地主机中进行了测试。此外,身份验证是使用电子邮件和密码而不是数字完成的,并且它返回一个包含 authentication_token
字段的 json。
关于iphone - 如何在 swift 中验证 iOS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37557201/