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.

235 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
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
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. FirebaseApp.configure()
  37. Fabric.with([Crashlytics.self])
  38. Fabric.sharedSDK().debug = true
  39. Messaging.messaging().delegate = self
  40. registerForNotification(application: application)
  41. setUUID()
  42. setupNavBar()
  43. setupStatusBar()
  44. setEntryPoint()
  45. isetupLanguage()
  46. if #available(iOS 10.0, *) {
  47. UNUserNotificationCenter.current().delegate = self
  48. } else {
  49. // Fallback on earlier versions
  50. }
  51. return true
  52. }
  53. private func isetupLanguage() {
  54. let language = UserDefaults.standard.string(forKey: AppConstants.currentLanguage)
  55. if (language != nil), let preferedDeviceLanguage = Locale.preferredLanguages.elementAt(index: 0), let _ = preferedDeviceLanguage.components(separatedBy: "-").first {
  56. Localize.setCurrentLanguage(language ?? "en")
  57. }
  58. }
  59. private func setUUID() {
  60. if UserDefaults.standard.string(forKey: AppConstants.uuid) == nil {
  61. let uuid = UUID().uuidString
  62. UserDefaults.standard.set(uuid, forKey: AppConstants.uuid)
  63. }
  64. }
  65. private func setupStatusBar() {
  66. // let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
  67. // if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
  68. // statusBar.backgroundColor = UIColor.blue
  69. // }
  70. }
  71. private func setupNavBar() {
  72. let appearance = UINavigationBar.appearance()
  73. appearance.backIndicatorImage = #imageLiteral(resourceName: "backIconBlack")
  74. appearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "backIconBlack")
  75. appearance.tintColor = UIColor.black
  76. }
  77. private func setEntryPoint() {
  78. let _default = UserDefaults.standard
  79. if let _ = _default.string(forKey: UserKeys.accessCode) {
  80. // user is logged in
  81. let mainWireFrame = MainWireframe.shared
  82. // self.window?.rootViewController =
  83. let tabBarViewController = mainWireFrame?.getMainView()
  84. let sidemenuVc = UIStoryboard(name: "SideMenu", bundle: nil).instantiateViewController(withIdentifier: "SideMenuViewController") as! SideMenuViewController
  85. //
  86. let sideMenuController = LGSideMenuController(rootViewController: tabBarViewController, leftViewController: sidemenuVc, rightViewController: nil)
  87. //
  88. sideMenuController.rootViewLayerShadowColor = UIColor(white: 0.9, alpha: 0.6)
  89. sideMenuController.rootViewLayerShadowRadius = 8.0
  90. sideMenuController.leftViewPresentationStyle = .scaleFromBig
  91. sideMenuController.leftViewWidth = UIScreen.main.bounds.width - 70.0
  92. if #available(iOS 10.0, *) {
  93. sideMenuController.leftViewBackgroundBlurEffect = UIBlurEffect(style: .regular)
  94. } else {
  95. // Fallback on earlier versions
  96. }
  97. window?.backgroundColor = sidemenuVc.view.backgroundColor
  98. self.window?.rootViewController = sideMenuController
  99. }else {
  100. // go to splashscreen
  101. let splashWireframe = SplashScreenWireframe()
  102. let nav = UINavigationController.init(rootViewController: splashWireframe.getMainView())
  103. self.window?.rootViewController = nav
  104. }
  105. }
  106. private func registerForNotification(application: UIApplication) {
  107. let settings: UIUserNotificationSettings =
  108. UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  109. application.registerForRemoteNotifications()
  110. application.registerUserNotificationSettings(settings)
  111. }
  112. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
  113. if userInfo[gcmMessageIDKey] != nil {
  114. }
  115. }
  116. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
  117. fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  118. }
  119. func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
  120. cmRegistrationId = fcmToken
  121. print(fcmToken)
  122. }
  123. func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
  124. print(remoteMessage.appData)
  125. }
  126. public func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
  127. }
  128. @available(iOS 10.0, *)
  129. func userNotificationCenter(_ center: UNUserNotificationCenter,
  130. willPresent notification: UNNotification,
  131. withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  132. var userInfo = notification.request.content.userInfo
  133. /**
  134. redirection of page after foreground push notification
  135. */
  136. if
  137. let aps = userInfo["aps"] as? NSDictionary,
  138. let alert = aps["alert"] as? NSDictionary,
  139. let body = alert["body"] as? String,
  140. let title = alert["title"] as? String {
  141. let image = UIImage.init(named: "ic_gme")
  142. let banner = Banner(title: title, subtitle: body, image: image, backgroundColor: UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0))
  143. banner.show(duration: 5.0)
  144. }
  145. if userInfo["code"] != nil {
  146. // print("codeAP delegate: \(codeID)")
  147. }
  148. // Change this to your preferred presentation option
  149. completionHandler(
  150. [UNNotificationPresentationOptions.alert,
  151. UNNotificationPresentationOptions.sound,
  152. UNNotificationPresentationOptions.badge])
  153. }
  154. func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  155. // print("Unable to register for remote notifications: \(error.localizedDescription)")
  156. }
  157. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  158. }
  159. /**
  160. method for redirection of page when push notification tap
  161. */
  162. func applicationDidEnterBackground(_ application: UIApplication) {
  163. let store = UserDefaults.standard
  164. let language = Localize.currentLanguage()
  165. store.set(language, forKey: AppConstants.currentLanguage)
  166. let viewcontroller = UIViewController()
  167. viewcontroller.view.backgroundColor = AppConstants.themeRedColor
  168. self.window?.rootViewController?.present(viewcontroller, animated: false, completion: nil)
  169. }
  170. func applicationWillEnterForeground(_ application: UIApplication) {
  171. if let language = UserDefaults.standard.string(forKey: AppConstants.currentLanguage) as? String {
  172. Localize.setCurrentLanguage(language)
  173. }
  174. self.window?.rootViewController?.dismiss(animated: false, completion: nil)
  175. }
  176. }