如何在 swift4 中集成忘记密码 api
How to integrate forget password api in swift4
这是我的第一个项目,我目前正在 doing.Here,我的任务是整合忘记密码 api.I 我不知道忘记 password.Can 谁能帮我做这个 task.If我知道流程,怎么做,怎么操作,那么提前me.Thank会容易一些
@IBAction func resetbutton(_ sender: Any) {
var email = emailtextfield.text
if email == ""{
let Alertcontroller = UIAlertController(title: "Alert", message: "Please Enter Email-Id", preferredStyle: .alert)
let CancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
Alertcontroller.addAction(CancelAction)
self.present(Alertcontroller, animated: true, completion: nil)
print(Alertcontroller)
}else {
postParameters = ["email":email]
Alamofire.request(Constants.Forgetpassword, method: .post, parameters: postParameters, encoding: URLEncoding.default, headers:nil).responseJSON { response in
switch response.result {
case .success:
print(response)
if response.result.value != nil{
}
break
case .failure(let error):
print(error)
}
}
}
}
按照以下步骤在您的中安装和创建 pod 文件
项目。
- https://blog.supereasyapps.com/cocoapods-tutorial-for-beginners-in-xcode-9-and-swift-4/(为网络服务调用安装 cocoa pod)
- 在您的 viewcontroller 中导入 Alamofire。
点击忘记密码按钮调用以下函数。
func apiCallForgotPassword(){
let todosEndpoint: String = "YOUR_API_URL"
//pass your required params
let dictParam: [String: Any] = ["email": "test@test.com"]
Alamofire.request(todosEndpoint, method: .post, parameters: dictParam,
encoding: JSONEncoding.default)
.responseJSON { response in
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling POST on /todos/1")
print(response.result.error!)
return
}
// make sure we got some JSON since that's what we expect
guard let json = response.result.value as? [String: Any] else {
print("didn't get todo object as JSON from API")
print("Error: \(response.result.error)")
return
}
// get and print the success message
guard let message = json["message"] as? String else {
print("Could not get todo title from JSON")
return
}
print("The message is: " + message)
}
}
这是我的第一个项目,我目前正在 doing.Here,我的任务是整合忘记密码 api.I 我不知道忘记 password.Can 谁能帮我做这个 task.If我知道流程,怎么做,怎么操作,那么提前me.Thank会容易一些
@IBAction func resetbutton(_ sender: Any) {
var email = emailtextfield.text
if email == ""{
let Alertcontroller = UIAlertController(title: "Alert", message: "Please Enter Email-Id", preferredStyle: .alert)
let CancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
Alertcontroller.addAction(CancelAction)
self.present(Alertcontroller, animated: true, completion: nil)
print(Alertcontroller)
}else {
postParameters = ["email":email]
Alamofire.request(Constants.Forgetpassword, method: .post, parameters: postParameters, encoding: URLEncoding.default, headers:nil).responseJSON { response in
switch response.result {
case .success:
print(response)
if response.result.value != nil{
}
break
case .failure(let error):
print(error)
}
}
}
}
按照以下步骤在您的中安装和创建 pod 文件 项目。
- https://blog.supereasyapps.com/cocoapods-tutorial-for-beginners-in-xcode-9-and-swift-4/(为网络服务调用安装 cocoa pod)
- 在您的 viewcontroller 中导入 Alamofire。
点击忘记密码按钮调用以下函数。
func apiCallForgotPassword(){ let todosEndpoint: String = "YOUR_API_URL" //pass your required params let dictParam: [String: Any] = ["email": "test@test.com"] Alamofire.request(todosEndpoint, method: .post, parameters: dictParam, encoding: JSONEncoding.default) .responseJSON { response in guard response.result.error == nil else { // got an error in getting the data, need to handle it print("error calling POST on /todos/1") print(response.result.error!) return } // make sure we got some JSON since that's what we expect guard let json = response.result.value as? [String: Any] else { print("didn't get todo object as JSON from API") print("Error: \(response.result.error)") return } // get and print the success message guard let message = json["message"] as? String else { print("Could not get todo title from JSON") return } print("The message is: " + message) } }