AppDelegate.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // AppDelegate.swift
  3. // TestQmeraLite
  4. //
  5. // Created by Qindi on 29/11/21.
  6. //
  7. import UIKit
  8. import NexilisLite
  9. import NotificationBannerSwift
  10. @main
  11. class AppDelegate: UIResponder, UIApplicationDelegate {
  12. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  13. var showButton = false
  14. if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_FLOATING || PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_MIX {
  15. showButton = true
  16. }
  17. Nexilis.connect(apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***", delegate: self, showButton: showButton, fromMAB: true) //51D0C44F35AD837B27B2970885F9AE731EB1F867F542DDA173AF31497E01037A(CBN Palio Mall) //1C4FA430BC9F44484AFBE99C8974D70B68CE7891DBE83505CBF01205DE51FC18(CBN)
  18. let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
  19. tabBarAppearance.configureWithTransparentBackground()
  20. if Bundle.main.displayName == "DigiNetS" {
  21. tabBarAppearance.backgroundColor = .black.withAlphaComponent(0.7)
  22. } else {
  23. tabBarAppearance.backgroundColor = .white.withAlphaComponent(0.9)
  24. }
  25. if #available(iOS 13.0, *) {
  26. UITabBar.appearance().standardAppearance = tabBarAppearance
  27. }
  28. if #available(iOS 15.0, *) {
  29. UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
  30. }
  31. UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
  32. let cancelButtonAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  33. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes , for: .normal)
  34. registerForPushNotifications()
  35. return true
  36. }
  37. // MARK: UISceneSession Lifecycle
  38. func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  39. // Called when a new scene session is being created.
  40. // Use this method to select a configuration to create the new scene with.
  41. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  42. }
  43. func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  44. Nexilis.destroyAll()
  45. // Called when the user discards a scene session.
  46. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  47. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  48. }
  49. private func registerForPushNotifications() {
  50. if #available(iOS 10.0, *) {
  51. let center = UNUserNotificationCenter.current()
  52. center.delegate = self
  53. center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
  54. if error == nil{
  55. DispatchQueue.main.async {
  56. UIApplication.shared.registerForRemoteNotifications()
  57. }
  58. }
  59. }
  60. }
  61. else {
  62. UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
  63. UIApplication.shared.registerForRemoteNotifications()
  64. }
  65. }
  66. }
  67. extension AppDelegate: ConnectDelegate, UNUserNotificationCenterDelegate {
  68. func onSuccess(userId: String) {
  69. print(#function, "userId: \(userId)")
  70. }
  71. func onFailed(error: String) {
  72. print(#function, "error: \(error)")
  73. }
  74. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  75. let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
  76. //print("TOKEN: \(deviceTokenString)")
  77. }
  78. func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  79. print(error)
  80. }
  81. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  82. let userInfo = response.notification.request.content.userInfo
  83. if let opposite = userInfo["opposite"] as? String {
  84. let user = User.getDataCanNil(pin: opposite)
  85. if user != nil {
  86. openEditorPersonal(opposite: opposite)
  87. } else {
  88. let group = Group.getData(group_id: opposite)
  89. let topic = Topic.getData(topic_id: opposite)
  90. if group != nil || topic != nil {
  91. openEditorGroup(opposite: opposite)
  92. }
  93. }
  94. }
  95. UIApplication.shared.applicationIconBadgeNumber = 0
  96. UNUserNotificationCenter.current().removeAllDeliveredNotifications()
  97. completionHandler()
  98. }
  99. func openEditorPersonal(opposite: String) {
  100. let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  101. editorPersonalVC.hidesBottomBarWhenPushed = true
  102. editorPersonalVC.unique_l_pin = opposite
  103. editorPersonalVC.fromNotification = true
  104. let onGoingCC = UserDefaults.standard.string(forKey: "onGoingCC") ?? ""
  105. if !onGoingCC.isEmpty {
  106. let compalintId = onGoingCC.components(separatedBy: ",")[2]
  107. let fPinCC = onGoingCC.isEmpty ? "" : onGoingCC.components(separatedBy: ",")[1]
  108. editorPersonalVC.isContactCenter = true
  109. editorPersonalVC.fPinContacCenter = fPinCC
  110. editorPersonalVC.complaintId = compalintId
  111. editorPersonalVC.onGoingCC = true
  112. editorPersonalVC.isRequestContactCenter = false
  113. }
  114. let navigationController = UINavigationController(rootViewController: editorPersonalVC)
  115. navigationController.modalPresentationStyle = .fullScreen
  116. navigationController.navigationBar.tintColor = .white
  117. navigationController.navigationBar.barTintColor = .mainColor
  118. navigationController.navigationBar.isTranslucent = false
  119. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  120. navigationController.navigationBar.barStyle = .black
  121. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  122. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  123. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  124. navigationController.navigationBar.titleTextAttributes = textAttributes
  125. navigationController.view.backgroundColor = .mainColor
  126. if UIApplication.shared.visibleViewController?.navigationController != nil {
  127. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  128. } else {
  129. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  130. }
  131. }
  132. func openEditorGroup(opposite: String) {
  133. let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "editorGroupVC") as! EditorGroup
  134. editorGroupVC.hidesBottomBarWhenPushed = true
  135. editorGroupVC.unique_l_pin = opposite
  136. editorGroupVC.fromNotification = true
  137. let navigationController = UINavigationController(rootViewController: editorGroupVC)
  138. navigationController.modalPresentationStyle = .fullScreen
  139. navigationController.navigationBar.tintColor = .white
  140. navigationController.navigationBar.barTintColor = .mainColor
  141. navigationController.navigationBar.isTranslucent = false
  142. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  143. navigationController.navigationBar.barStyle = .black
  144. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  145. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  146. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  147. navigationController.navigationBar.titleTextAttributes = textAttributes
  148. navigationController.view.backgroundColor = .mainColor
  149. if UIApplication.shared.visibleViewController?.navigationController != nil {
  150. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  151. } else {
  152. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  153. }
  154. }
  155. }