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.

237 lines
8.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // AppDelegate.swift
  3. // GMERemittance
  4. //
  5. // Created by Fm-user on 11/30/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import Firebase
  10. import FirebaseAuth
  11. import UserNotifications
  12. import FirebaseInstanceID
  13. import FirebaseMessaging
  14. import BRYXBanner
  15. import Fabric
  16. import Crashlytics
  17. import AlamofireNetworkActivityLogger
  18. import IQKeyboardManagerSwift
  19. import LGSideMenuController
  20. import Localize_Swift
  21. let server: Server = .stagging
  22. @UIApplicationMain
  23. class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
  24. var window: UIWindow?
  25. let gcmMessageIDKey = "gcm_message_id"
  26. var firstTranscationStatusForHome:Bool?
  27. var firstTranscationStatusForProfileForm:Bool?
  28. var cmRegistrationId: String?
  29. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  30. UIApplication.shared.applicationIconBadgeNumber = 0
  31. firstTranscationStatusForHome = true
  32. firstTranscationStatusForProfileForm = true
  33. NetworkActivityLogger.shared.startLogging()
  34. NetworkActivityLogger.shared.level = .debug
  35. IQKeyboardManager.shared.enable = true
  36. IQKeyboardManager.shared.shouldResignOnTouchOutside = true
  37. FirebaseApp.configure()
  38. Fabric.with([Crashlytics.self])
  39. Fabric.sharedSDK().debug = true
  40. Messaging.messaging().delegate = self
  41. registerForNotification(application: application)
  42. setUUID()
  43. setupNavBar()
  44. setupStatusBar()
  45. setEntryPoint()
  46. isetupLanguage()
  47. if #available(iOS 10.0, *) {
  48. UNUserNotificationCenter.current().delegate = self
  49. } else {
  50. // Fallback on earlier versions
  51. }
  52. return true
  53. }
  54. private func isetupLanguage() {
  55. let language = UserDefaults.standard.string(forKey: AppConstants.currentLanguage)
  56. if (language != nil), let preferedDeviceLanguage = Locale.preferredLanguages.elementAt(index: 0), let _ = preferedDeviceLanguage.components(separatedBy: "-").first {
  57. Localize.setCurrentLanguage(language ?? "en")
  58. }
  59. }
  60. private func setUUID() {
  61. if UserDefaults.standard.string(forKey: AppConstants.uuid) == nil {
  62. let uuid = UUID().uuidString
  63. UserDefaults.standard.set(uuid, forKey: AppConstants.uuid)
  64. }
  65. }
  66. private func setupStatusBar() {
  67. // let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
  68. // if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
  69. // statusBar.backgroundColor = UIColor.blue
  70. // }
  71. }
  72. private func setupNavBar() {
  73. let appearance = UINavigationBar.appearance()
  74. appearance.backIndicatorImage = #imageLiteral(resourceName: "backIconBlack")
  75. appearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "backIconBlack")
  76. appearance.tintColor = UIColor.black
  77. }
  78. private func setEntryPoint() {
  79. let _default = UserDefaults.standard
  80. if let _ = _default.string(forKey: UserKeys.accessCode) {
  81. let biometricAuthenticationWireframe = BiometricAuthenticationWireframe()
  82. biometricAuthenticationWireframe.information = "Please enter authentication information for login"
  83. biometricAuthenticationWireframe.completion = { [weak self] error in
  84. if error != nil {
  85. print("BiometricAuthenticationWireframe Error: \(error!)")
  86. } else {
  87. // user is logged in
  88. let mainWireFrame = MainWireframe.shared
  89. // self.window?.rootViewController =
  90. let tabBarViewController = mainWireFrame?.getMainView()
  91. let sidemenuVc = UIStoryboard(name: "SideMenu", bundle: nil).instantiateViewController(withIdentifier: "SideMenuViewController") as! SideMenuViewController
  92. //
  93. let sideMenuController = LGSideMenuController(rootViewController: tabBarViewController, leftViewController: sidemenuVc, rightViewController: nil)
  94. //
  95. sideMenuController.rootViewLayerShadowColor = UIColor(white: 0.9, alpha: 0.6)
  96. sideMenuController.rootViewLayerShadowRadius = 8.0
  97. sideMenuController.leftViewPresentationStyle = .scaleFromBig
  98. sideMenuController.leftViewWidth = UIScreen.main.bounds.width - 70.0
  99. if #available(iOS 10.0, *) {
  100. sideMenuController.leftViewBackgroundBlurEffect = UIBlurEffect(style: .regular)
  101. } else {
  102. // Fallback on earlier versions
  103. }
  104. self?.window?.backgroundColor = sidemenuVc.view.backgroundColor
  105. self?.window?.rootViewController = sideMenuController
  106. }
  107. }
  108. let authViewController = biometricAuthenticationWireframe.getMainView()
  109. self.window?.rootViewController = authViewController
  110. } else {
  111. // go to splashscreen
  112. let splashWireframe = SplashScreenWireframe()
  113. let nav = UINavigationController.init(rootViewController: splashWireframe.getMainView())
  114. self.window?.rootViewController = nav
  115. }
  116. }
  117. private func registerForNotification(application: UIApplication) {
  118. let settings: UIUserNotificationSettings =
  119. UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  120. application.registerForRemoteNotifications()
  121. application.registerUserNotificationSettings(settings)
  122. }
  123. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
  124. if userInfo[gcmMessageIDKey] != nil {
  125. }
  126. }
  127. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
  128. fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  129. }
  130. func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
  131. cmRegistrationId = fcmToken
  132. print(fcmToken)
  133. }
  134. func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
  135. print(remoteMessage.appData)
  136. }
  137. public func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
  138. }
  139. @available(iOS 10.0, *)
  140. func userNotificationCenter(_ center: UNUserNotificationCenter,
  141. willPresent notification: UNNotification,
  142. withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  143. var userInfo = notification.request.content.userInfo
  144. // if let aps = userInfo["aps"] as? NSDictionary,
  145. // let alert = aps["alert"] as? NSDictionary,
  146. // let body = alert["body"] as? String,
  147. // let title = alert["title"] as? String {
  148. // let image = UIImage.init(named: "ic_gme")
  149. // let banner = Banner(title: title, subtitle: body, image: image, backgroundColor: UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0))
  150. // banner.show(duration: 5.0)
  151. // }
  152. completionHandler(
  153. [UNNotificationPresentationOptions.alert,
  154. UNNotificationPresentationOptions.sound,
  155. UNNotificationPresentationOptions.badge])
  156. }
  157. func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  158. // print("Unable to register for remote notifications: \(error.localizedDescription)")
  159. }
  160. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  161. }
  162. /**
  163. method for redirection of page when push notification tap
  164. */
  165. func applicationDidEnterBackground(_ application: UIApplication) {
  166. let store = UserDefaults.standard
  167. let language = Localize.currentLanguage()
  168. store.set(language, forKey: AppConstants.currentLanguage)
  169. let viewcontroller = UIViewController()
  170. viewcontroller.view.backgroundColor = AppConstants.themeRedColor
  171. self.window?.rootViewController?.present(viewcontroller, animated: false, completion: nil)
  172. }
  173. func applicationWillEnterForeground(_ application: UIApplication) {
  174. if let language = UserDefaults.standard.string(forKey: AppConstants.currentLanguage) {
  175. Localize.setCurrentLanguage(language)
  176. }
  177. self.window?.rootViewController?.dismiss(animated: false, completion: nil)
  178. }
  179. }