// // UIExtension.swift // GMERemittance // // Created by Sujal on 12/11/17. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved. // import Foundation import UIKit import MBProgressHUD // ccr // MARK: Alerts extension UIViewController { func confirmationAlert(title: String, message: String, confirmTitle: String, style: UIAlertActionStyle = .destructive, confirmAction: @escaping () -> Void) { let deleteActionSheetController = UIAlertController(title: title, message: message, preferredStyle: .alert) let deleteAction = UIAlertAction(title: confirmTitle, style: style) { action -> Void in confirmAction() } let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in } deleteActionSheetController.addAction(deleteAction) deleteActionSheetController.addAction(cancelAction) self.present(deleteActionSheetController, animated: true, completion: nil) } func alert(message: String?, title: String? = "Alert!", okAction: (()->())? = nil) { let alertController = getAlert(message: message, title: title) alertController.addAction(title: "Ok", handler: okAction) self.present(alertController, animated: true, completion: nil) } func alertWithOkCancel(message: String?, title: String? = "Error", okTitle: String? = "Ok", style: UIAlertControllerStyle? = .alert, cancelTitle: String? = "Cancel", OkStyle: UIAlertActionStyle = .default, cancelStyle: UIAlertActionStyle = .default, okAction: (()->())? = nil, cancelAction: (()->())? = nil) { let alertController = getAlert(message: message, title: title, style: style) alertController.addAction(title: okTitle,style: OkStyle, handler: okAction) alertController.addAction(title: cancelTitle, style: cancelStyle, handler: cancelAction) self.present(alertController, animated: true, completion: nil) } func alertWithOk(message: String?, title: String? = "Error", okTitle: String? = "Ok", style: UIAlertControllerStyle? = .alert, OkStyle: UIAlertActionStyle = .default, okAction: (()->())? = nil) { let alertController = getAlert(message: message, title: title, style: style) alertController.addAction(title: okTitle,style: OkStyle, handler: okAction) self.present(alertController, animated: true, completion: nil) } private func getAlert(message: String?, title: String?, style: UIAlertControllerStyle? = .alert) -> UIAlertController { return UIAlertController(title: title, message: message, preferredStyle: style ?? .alert) } func present(_ alert: UIAlertController, asActionsheetInSourceView sourceView: Any) { if UI_USER_INTERFACE_IDIOM() == .pad { alert.modalPresentationStyle = .popover if let presenter = alert.popoverPresentationController { if sourceView is UIBarButtonItem { presenter.barButtonItem = sourceView as? UIBarButtonItem }else if sourceView is UIView { let view = sourceView as! UIView presenter.sourceView = view presenter.sourceRect = view.bounds } } } self.present(alert, animated: true, completion: nil) } } extension UIAlertController { func addAction(title: String?, style: UIAlertActionStyle = .default, handler: (()->())? = nil) { let action = UIAlertAction(title: title, style: style, handler: {_ in handler?() }) self.addAction(action) } } struct Associate { static var hud: UInt8 = 0 } // MARK: HUD extension UIViewController { private func setProgressHud() -> MBProgressHUD { let progressHud: MBProgressHUD = MBProgressHUD.showAdded(to: self.view, animated: true) progressHud.tintColor = UIColor.darkGray progressHud.removeFromSuperViewOnHide = true objc_setAssociatedObject(self, &Associate.hud, progressHud, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) return progressHud } var progressHud: MBProgressHUD { if let progressHud = objc_getAssociatedObject(self, &Associate.hud) as? MBProgressHUD { progressHud.isUserInteractionEnabled = true return progressHud } return setProgressHud() } var progressHudIsShowing: Bool { return self.progressHud.isHidden } func showProgressHud() { self.progressHud.show(animated: false) } func hideProgressHud() { self.progressHud.label.text = "" self.progressHud.completionBlock = { objc_setAssociatedObject(self, &Associate.hud, nil, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) } self.progressHud.hide(animated: false) } } // ccr extension UIViewController { func prepareAlert(title: String, message: String) -> UIAlertController { let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) return alert } func showActivityIndicator(activityIndicator: UIActivityIndicatorView) { activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray activityIndicator.center = view.center activityIndicator.hidesWhenStopped = true view.addSubview(activityIndicator) activityIndicator.startAnimating() } func dismissActivityIndicator(activityIndicator: UIActivityIndicatorView) { activityIndicator.stopAnimating() } func hideKeyboardWhenTappedAround() { let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) tap.cancelsTouchesInView = false view.addGestureRecognizer(tap) } @objc func dismissKeyboard() { view.endEditing(true) } func setUpNavBar(id: Int, title:String) { switch id { case 99: //Settings Screen self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black case 201: self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.title = title self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] case 202: self.navigationItem.hidesBackButton = true self.navigationController?.navigationBar.barTintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white] self.navigationController?.navigationBar.titleTextAttributes = textAttributes self.navigationItem.title = title self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white case 203: self.navigationItem.hidesBackButton = true self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.title = title case 300: // self.navigationItem.hidesBackButton = true self.navigationController?.navigationBar.barTintColor = UIColor(hex: 0xec1c24) self.navigationItem.title = title self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white] //TRACK TO SEND MONEY case 204: self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: " ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.title = title self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] case 205: self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.title = title self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] case 206: self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.title = title self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] /// to handle back after redirection from push notification case 207 : self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.title = title self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] // push notification for no cancel bottom case 208: self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: " ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.title = title self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] case 0: self.navigationController?.navigationBar.barTintColor = UIColor(hex: 0xec1c24) self.navigationController?.navigationBar.isTranslucent = false self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) self.navigationController?.navigationBar.shadowImage = UIImage() //added for autop login cottection self.navigationItem.hidesBackButton = true /** used for recipient form while clicking cancel button redirect to back view */ case 1: self.navigationItem.title = "Send Money" self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] /** used for send Money while clicking back button redirect to home view during both fron tabbar and menu botton */ case 2: self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:" ", style:.plain, target:nil, action:nil) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.goToHomeScreen)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.black self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.title = title self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black] case 3: self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.title = "Exchange Rate" self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) case 4: self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.title = "Wallet to Wallet Transfer" self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) /* for social page navigation */ case 5: self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "backIconBlack") self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white] case 6: self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(UIViewController.goToHomeScreen)) self.navigationItem.title = "Agent" self.navigationItem.rightBarButtonItem?.tintColor = UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0) case 200: let height: CGFloat = 516 //whatever height you want to add to the existing height let bounds = self.navigationController!.navigationBar.bounds self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height) //CASE 100 is for before KYC screen where back should not be enabled case 100: self.navigationItem.hidesBackButton = true let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 125, height: 30)) imageView.contentMode = .scaleAspectFit let image = UIImage(named: "ic_gme_new") imageView.image = image self.navigationItem.titleView = imageView case 101: self.navigationItem.hidesBackButton = true self.navigationController?.navigationBar.isTranslucent = true //self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) //self.navigationController?.navigationBar.shadowImage = UIImage() case 102: self.navigationItem.hidesBackButton = true self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "ic_rect"), for: .default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xed1c24) self.navigationController?.navigationBar.isTranslucent = false let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 30)) imageView.contentMode = .scaleAspectFit let image = UIImage(named: "ic_gme") imageView.image = image navigationItem.titleView = imageView case 103: self.navigationItem.hidesBackButton = true self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "ic_rect"), for: .default) self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xec1c24) let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 30)) imageView.contentMode = .scaleAspectFit let image = UIImage(named: "ic_gme") imageView.image = image navigationItem.titleView = imageView case 104: self.navigationItem.hidesBackButton = true self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIconBlack"), style: .plain, target: self, action: #selector(self.handleBack)) self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "ic_rect"), for: .default) self.navigationController?.navigationBar.barTintColor = UIColor(hex:0xec1c24) let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 30)) imageView.contentMode = .scaleAspectFit let image = UIImage(named: "ic_gme") imageView.image = image navigationItem.titleView = imageView case 105: self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default) self.navigationController?.navigationBar.barTintColor = UIColor.white self.navigationController?.navigationBar.isTranslucent = false default: return } } @objc func goToHomeScreen() { showHomeScreen() } func showHomeScreen() { let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main) if let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as? UITabBarController { self.navigationController!.pushViewController(tabViewController, animated: false) } } func showHomeScreen2() { let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main) if let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as? UITabBarController { let destinationViewController = tabViewController.viewControllers![0] as! HomeViewController destinationViewController.numberCellsInCollectionView = 6 destinationViewController.showAllCollectionViewCells = true destinationViewController.hidesBottomBarWhenPushed = false // self.navigationController!.pushViewController(destinationViewController, animated: false) self.navigationController!.pushViewController(tabViewController, animated: false) } } func enableUserInteractions() { self.view.isUserInteractionEnabled = true self.navigationController?.navigationBar.isUserInteractionEnabled = true self.navigationController?.view.isUserInteractionEnabled = true } func disableUserInteractions() { self.view.isUserInteractionEnabled = false self.navigationController?.navigationBar.isUserInteractionEnabled = false self.navigationController?.view.isUserInteractionEnabled = false } func unixTimeStampToDate(unixTimeStamp: String) -> String { let date = Date(timeIntervalSince1970: TimeInterval(unixTimeStamp)!) let dateFormatter = DateFormatter() dateFormatter.timeZone = TimeZone(abbreviation: "GMT") //Set timezone that you want dateFormatter.locale = NSLocale.current dateFormatter.dateFormat = "dd/MM/yyyy" //Specify your format that you want return dateFormatter.string(from: date) } func firstWord(text: String) -> String{ let word = text var firstWord = "" if let index = word.range(of: " ")?.lowerBound { let substring = word[.. String { if let userId = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String { return userId } return "" } // func getFullName() -> String { // if let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as? String { // return fullName // } // return "" // } // func getNickNameOrFirstName() -> String { // let nickName = UserDefaults.standard.object(forKey: "com.gmeremit.nickName") as! String // if nickName != "" { // return nickName // } // let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as! String // return fullName.components(separatedBy: " ").first! // } func getFirstName() -> String { let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as! String return fullName.components(separatedBy: " ").first! } func getFullName() -> String { if let fullName = UserDefaults.standard.object(forKey: "com.gmeremit.fullName") as? String { return fullName } return "" } func isVerified() -> Bool { if let verified = UserDefaults.standard.object(forKey: "com.gmeremit.isVerified") as? Bool { return verified } return false } func isKYCSubmitted() -> Bool { if let verified = UserDefaults.standard.object(forKey: "com.gmeremit.isKYCSubmitted") as? Bool { return verified } return false } // func setupKeyboardNotification() { // NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil) // NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil) // } // // @objc func keyboardWillShow(notification: NSNotification) { // if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { // if self.view.frame.origin.y == 0{ // self.view.frame.origin.y -= keyboardSize.height // } // } // } // @objc func keyboardWillShow(notification: NSNotification) { // //self.scrollView.isScrollEnabled = true // var info = notification.userInfo! // let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size // let contentInsets : UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize!.height, 0.0) // // self.scrollView.contentInset = contentInsets // self.scrollView.scrollIndicatorInsets = contentInsets // // var aRect : CGRect = self.view.frame // aRect.size.height -= keyboardSize!.height // if let activeField = self.activeField { // if (!aRect.contains(activeField.frame.origin)){ // self.scrollView.scrollRectToVisible(activeField.frame, animated: true) // } // } // } // // @objc func keyboardWillHide(notification: NSNotification) { // if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { // if self.view.frame.origin.y != 0{ // self.view.frame.origin.y += keyboardSize.height // } // } // } @objc func handleBack(){ self.navigationController?.popViewController(animated: true) } func getCommaAddedAmountString(amountString: String) -> String { let separatorString = " " let numberFormatter = NumberFormatter() numberFormatter.numberStyle = NumberFormatter.Style.decimal if amountString.contains(separatorString) { let splittedArray = amountString.split(separator: " ") let number = Double(splittedArray[0])! let formattedNumber = numberFormatter.string(from: NSNumber(value:number)) return formattedNumber! + " " + splittedArray[1] } else { let formattedNumber = numberFormatter.string(from: NSNumber(value: Double(amountString)!)) return formattedNumber! } } func setUpAnotherLoginListener(genericviewmodel: ModelExtension) { genericviewmodel.anotherLogin.bind { [weak self] in guard let context = self else { return } guard $0 != nil else { return } if $0! { context.view.endEditing(true) context.enableUserInteractions() context.logOutUser() } } } func logOutUser() { UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!) UserDefaults.standard.synchronize() let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.firstTranscationStatusForHome = true appDelegate.firstTranscationStatusForProfileForm = true UserDefaults.standard.set(false, forKey: "com.gmeremit.loginStatus") UserDefaults.standard.removeObject(forKey: "com.gmeremit.dpUrl") UserDefaults.standard.removeObject(forKey: "com.gmeremit.walletNumber") UserDefaults.standard.removeObject(forKey: "com.gmeremit.bankName") UserDefaults.standard.removeObject(forKey: "com.gmeremit.fullName") // UserDefaults.standard.removeObject(forKey: "com.gmeremit.accessCode") UserDefaults.standard.removeObject(forKey: "com.gmeremit.username") UserDefaults.standard.removeObject(forKey: "com.gmeremit.nickName") UserDefaults.standard.removeObject(forKey: "com.gmeremit.balance") UserDefaults.standard.removeObject(forKey: "com.gmeremit.rewardPoint") UserDefaults.standard.removeObject(forKey: "com.gmeremit.isVerified") UserDefaults.standard.removeObject(forKey: "com.gmeremit.isKYCSubmitted") UserDefaults.standard.removeObject(forKey: "com.gmeremit.email") UserDefaults.standard.removeObject(forKey: "com.gmeremit.mobileNumber") UserDefaults.standard.removeObject(forKey: "com.gmeremit.password") UserDefaults.standard.removeObject(forKey: " com.gmeremit.isReferred") let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main) let vController = storyboard.instantiateViewController(withIdentifier: "SplashScreenViewController") as! SplashScreenViewController self.navigationController?.navigationBar.isHidden = false self.navigationController!.pushViewController(vController, animated: false) } }