AppDelegate.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.isShowForceSignIn = false
  18. APIS.connect(appName: Bundle.main.infoDictionary?["CFBundleName"] as! String , apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***", delegate: self, showButton: showButton, fromMAB: true) //23091CF494A11149F5A8FC8D17FF690DC69AE656F91B86070A11506ED24144F5(BPKH) //38747683290F62E9667A018F490396EAE47BC16ADECD85B7E865C733E6DBD6A2(OneApp)
  19. registerForPushNotifications()
  20. return true
  21. }
  22. // MARK: UISceneSession Lifecycle
  23. func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  24. // Called when a new scene session is being created.
  25. // Use this method to select a configuration to create the new scene with.
  26. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  27. }
  28. func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  29. Nexilis.destroyAll()
  30. // Called when the user discards a scene session.
  31. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  32. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  33. }
  34. private func registerForPushNotifications() {
  35. if #available(iOS 10.0, *) {
  36. let center = UNUserNotificationCenter.current()
  37. center.delegate = self
  38. center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
  39. if error == nil{
  40. DispatchQueue.main.async {
  41. UIApplication.shared.registerForRemoteNotifications()
  42. }
  43. }
  44. }
  45. }
  46. else {
  47. UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
  48. UIApplication.shared.registerForRemoteNotifications()
  49. }
  50. }
  51. }
  52. extension AppDelegate: ConnectDelegate, UNUserNotificationCenterDelegate {
  53. func onSuccess(userId: String) {
  54. //print(#function, "userId: \(userId)")
  55. }
  56. func onFailed(error: String) {
  57. //print(#function, "error: \(error)")
  58. }
  59. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  60. let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
  61. //print("TOKEN: \(deviceTokenString)")
  62. }
  63. func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  64. //print(error)
  65. }
  66. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  67. let userInfo = response.notification.request.content.userInfo
  68. if let opposite = userInfo["opposite"] as? String {
  69. let user = User.getDataCanNil(pin: opposite)
  70. if user != nil {
  71. openEditorPersonal(opposite: opposite)
  72. } else {
  73. let group = Group.getData(group_id: opposite)
  74. let topic = Topic.getData(topic_id: opposite)
  75. if group != nil || topic != nil {
  76. openEditorGroup(opposite: opposite)
  77. }
  78. }
  79. }
  80. UIApplication.shared.applicationIconBadgeNumber = 0
  81. UNUserNotificationCenter.current().removeAllDeliveredNotifications()
  82. completionHandler()
  83. }
  84. func openEditorPersonal(opposite: String) {
  85. let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  86. editorPersonalVC.hidesBottomBarWhenPushed = true
  87. editorPersonalVC.unique_l_pin = opposite
  88. editorPersonalVC.fromNotification = true
  89. let onGoingCC: String = SecureUserDefaults.shared.value(forKey: "onGoingCC") ?? ""
  90. if !onGoingCC.isEmpty {
  91. let compalintId = onGoingCC.components(separatedBy: ",")[2]
  92. let fPinCC = onGoingCC.isEmpty ? "" : onGoingCC.components(separatedBy: ",")[1]
  93. editorPersonalVC.isContactCenter = true
  94. editorPersonalVC.fPinContacCenter = fPinCC
  95. editorPersonalVC.complaintId = compalintId
  96. editorPersonalVC.onGoingCC = true
  97. editorPersonalVC.isRequestContactCenter = false
  98. }
  99. let navigationController = CustomNavigationController(rootViewController: editorPersonalVC)
  100. navigationController.modalPresentationStyle = .fullScreen
  101. navigationController.navigationBar.tintColor = .white
  102. navigationController.navigationBar.barTintColor = UIApplication.shared.visibleViewController?.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  103. navigationController.navigationBar.isTranslucent = false
  104. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  105. navigationController.navigationBar.barStyle = .black
  106. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  107. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  108. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  109. navigationController.navigationBar.titleTextAttributes = textAttributes
  110. if UIApplication.shared.visibleViewController?.navigationController != nil {
  111. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  112. } else {
  113. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  114. }
  115. }
  116. func openEditorGroup(opposite: String) {
  117. let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "editorGroupVC") as! EditorGroup
  118. editorGroupVC.hidesBottomBarWhenPushed = true
  119. editorGroupVC.unique_l_pin = opposite
  120. editorGroupVC.fromNotification = true
  121. let navigationController = CustomNavigationController(rootViewController: editorGroupVC)
  122. navigationController.modalPresentationStyle = .fullScreen
  123. navigationController.navigationBar.tintColor = .white
  124. navigationController.navigationBar.barTintColor = UIApplication.shared.visibleViewController?.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  125. navigationController.navigationBar.isTranslucent = false
  126. navigationController.navigationBar.overrideUserInterfaceStyle = .dark
  127. navigationController.navigationBar.barStyle = .black
  128. let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
  129. UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
  130. let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  131. navigationController.navigationBar.titleTextAttributes = textAttributes
  132. if UIApplication.shared.visibleViewController?.navigationController != nil {
  133. UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
  134. } else {
  135. UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
  136. }
  137. }
  138. }