You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

6 years ago
  1. //
  2. // HomeViewModel.swift
  3. // GMERemittance
  4. //
  5. // Created by FMI-12 on 3/5/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class HomeViewModel: ModelExtension {
  10. let userId = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String
  11. var cmRegisteredId: Box<Bool?> = Box(nil)
  12. var homeConnectionTimeOut: Box<Bool?> = Box(nil)
  13. /**
  14. To set cm registration Id
  15. - parameter cmRegistrationId: id
  16. */
  17. func cmRegistrationId(cmRegistrationId: String) {
  18. if !Reachability.isConnectedToNetwork() {
  19. self.internetConnection.value = false
  20. } else {
  21. RestApiMananger.sharedInstance.getcmRegistrationId(userId: userId!, cmRegistrationId: cmRegistrationId) { result in
  22. switch result {
  23. case .success(_):
  24. self.cmRegisteredId.value = true
  25. case let .failure(errorJSON):
  26. self.setErrorMessage(message: errorJSON["message"].stringValue)
  27. self.cmRegisteredId.value = false
  28. case .updateAccessCode:
  29. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  30. result in
  31. if result != "Error"{
  32. let uuid = RestApiMananger.sharedInstance.getUUID()
  33. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  34. self.cmRegistrationId(cmRegistrationId: cmRegistrationId)
  35. }
  36. }
  37. case .logOutUser:
  38. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  39. self.anotherLogin.value = true
  40. case .timeOut:
  41. self.homeConnectionTimeOut.value = false
  42. }
  43. }
  44. }
  45. }
  46. }