Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Calling Function code to generate OTP
- @IBAction func loginButtonTapped(_ sender: AnyObject) {
- print("mobile",self.textFieldPhoneNum.text!)
- guard (textFieldName.text?.characters.count)! > 0 && (textFieldPhoneNum.text?.characters.count)! == 10 else {
- _ = SCLAlertView().showError(errText, subTitle: INPUT_PHONE_ERR,closeButtonTitle: closeButtonTitle, colorStyle : SCLAlertViewStyle.easyPolicy.defaultColorInt)
- return
- }
- self.nsConstantMethods.putString(key: NS_NAME_KEY,value: textFieldName.text!)
- self.nsConstantMethods.putString(key: NS_PHONE_KEY,value: textFieldPhoneNum.text!)
- self.loginAPIManager.generateOTPService(name: textFieldName.text!,epAppRegID: "", mobile: self.textFieldPhoneNum.text!, success: { (data) -> Void in
- SVProgressHUD.dismiss()
- self.loginRespnse = data!
- self.nsConstantMethods.putInt(key: NS_CUSTOMERID_KEY,value: self.loginRespnse.customerId)
- DispatchQueue.main.async {
- self.openOTPPopup()
- }
- }, failure: { (data) -> Void in
- SVProgressHUD.dismiss()
- })
- }
- //Function being called to generate OTP
- import Foundation
- import Swift
- import Alamofire
- import AlamofireObjectMapper
- import ObjectMapper
- import SVProgressHUD
- public class LoginAPIManager {
- var otp : Int! = 0
- func generateOTPService(name : String,epAppRegID: String, mobile: String, success: @escaping (_ data: LoginResponse?) -> Void,failure: @escaping (_ _data: AnyObject?) -> Void) -> Void{
- print("mobile no ",mobile)
- let otpGenratorModel = LoginOTP()
- otpGenratorModel.login = OTPModel()
- otpGenratorModel.login.mobile = mobile
- otpGenratorModel.login.deviceID = DEVICE_ID
- otpGenratorModel.login.name = name
- otpGenratorModel.login.epAppRegID = epAppRegID
- let i = Mapper<LoginOTP>().toJSON(otpGenratorModel)
- print("i",i.debugDescription)
- let otpResponse = OTPResponse()
- SVProgressHUD.show(withStatus: "Loading")
- SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)
- SVProgressHUD.setRingThickness(0.8)
- SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.black)
- //network request to generate OTP
- Alamofire.request(BASE_URL + OTP_GENRATOR_URL, method: .post, parameters: i, encoding: JSONEncoding.default).responseObject( mapToObject: otpResponse) { responseObj in
- //switch to valide response
- switch responseObj.result{
- case .success(_):
- print("otp respoose",otpResponse.errorCode)
- //nested switch to validate response code
- switch otpResponse.errorCode{
- case SUCCESS_CODE?:
- DispatchQueue.global(qos: .background).async {
- success(otpResponse.loginResponse)
- }
- self.otp = Int(otpResponse.loginResponse.OTP)!
- print("self.otp ",self.otp,otpResponse.loginResponse.OTP)
- break
- case DEFAULT_ERR_CODE?:
- _ = SCLAlertView().showError(errText, subTitle: errSubtext,closeButtonTitle: closeButtonTitle, colorStyle : SCLAlertViewStyle.easyPolicy.defaultColorInt)
- failure("default error" as AnyObject?)
- break
- case TIMEOUT_ERR?:
- _ = SCLAlertView().showError(timeOutErr, subTitle: errSubtext,closeButtonTitle: closeButtonTitle, colorStyle : SCLAlertViewStyle.easyPolicy.defaultColorInt)
- failure("Timeout error" as AnyObject?)
- break
- default :
- _ = SCLAlertView().showError(errText, subTitle: errSubtext,closeButtonTitle: closeButtonTitle, colorStyle : SCLAlertViewStyle.easyPolicy.defaultColorInt)
- failure("default error" as AnyObject?)
- break
- }
- break
- case .failure(let error):
- guard (error as NSError?) != nil else{
- return
- }
- print(error.localizedDescription)
- _ = SCLAlertView().showError("Oops Something Went wrong", subTitle: error.localizedDescription,closeButtonTitle:"OK", colorStyle : SCLAlertViewStyle.easyPolicy.defaultColorInt)
- break
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment