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.

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