iphone - 如何在 swift 中验证 iOS 应用程序

标签 iphone xcode swift active-directory restful-authentication

我想知道如何快速验证我制作的自定义服务的 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/

相关文章:

ios7 所有 searchviews 和 tableviews 关闭 20 像素

javascript - iPhone 自动化 - 如何在 "a.js"中导入 "b.js"?

ios - XCode 4.2 story builder 的 "Defines Context"和 "Provide Context"是什么意思?

ios - 生成未签名的 IPA iOS 应用程序

iphone - 如何将我的 iOS 项目限制为仅限 iPhone 4

ios - 在 ios 9.1 中运行我的旧项目时显示此错误。iPhoneOS9.1.sdk/usr/lib/libsqlite3.dylib (没有这样的文件或目录)

string - 在 Swift 中快速转义 unicode 字符

iphone - UIButton Action 不使用 UITapGestureRecognizer iPhone 应用程序调用?

ios - 使用PrepareForSegue方法从一个UITableView传递到另一个UITableView

ios - iOS Scrumdinger 教程中的 ThemePicker 不显示 ThemeView 颜色