| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // AppDelegate.swift
- // TestQmeraLite
- //
- // Created by Qindi on 29/11/21.
- //
- import UIKit
- import NexilisLite
- import NotificationBannerSwift
- @main
- class AppDelegate: UIResponder, UIApplicationDelegate {
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- var showButton = false
- if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_FLOATING || PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_MIX {
- showButton = true
- }
- Nexilis.connect(apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***", delegate: self, showButton: showButton, fromMAB: true) //51D0C44F35AD837B27B2970885F9AE731EB1F867F542DDA173AF31497E01037A(CBN Palio Mall) //1C4FA430BC9F44484AFBE99C8974D70B68CE7891DBE83505CBF01205DE51FC18(CBN)
- let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
- tabBarAppearance.configureWithTransparentBackground()
- if Bundle.main.displayName == "DigiNetS" {
- tabBarAppearance.backgroundColor = .black.withAlphaComponent(0.7)
- } else {
- tabBarAppearance.backgroundColor = .white.withAlphaComponent(0.9)
- }
- if #available(iOS 13.0, *) {
- UITabBar.appearance().standardAppearance = tabBarAppearance
- }
- if #available(iOS 15.0, *) {
- UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
- }
- UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
- let cancelButtonAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes , for: .normal)
- registerForPushNotifications()
- return true
- }
- // MARK: UISceneSession Lifecycle
- func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
- // Called when a new scene session is being created.
- // Use this method to select a configuration to create the new scene with.
- return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
- }
- func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
- Nexilis.destroyAll()
- // Called when the user discards a scene session.
- // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
- // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
- }
-
- private func registerForPushNotifications() {
- if #available(iOS 10.0, *) {
- let center = UNUserNotificationCenter.current()
- center.delegate = self
- center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
- if error == nil{
- DispatchQueue.main.async {
- UIApplication.shared.registerForRemoteNotifications()
- }
- }
- }
- }
- else {
- UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
- UIApplication.shared.registerForRemoteNotifications()
- }
- }
- }
- extension AppDelegate: ConnectDelegate, UNUserNotificationCenterDelegate {
-
- func onSuccess(userId: String) {
- print(#function, "userId: \(userId)")
- }
-
- func onFailed(error: String) {
- print(#function, "error: \(error)")
- }
-
- func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
- let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
- //print("TOKEN: \(deviceTokenString)")
- }
-
- func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
- print(error)
- }
-
- func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
- let userInfo = response.notification.request.content.userInfo
- if let opposite = userInfo["opposite"] as? String {
- let user = User.getDataCanNil(pin: opposite)
- if user != nil {
- openEditorPersonal(opposite: opposite)
- } else {
- let group = Group.getData(group_id: opposite)
- let topic = Topic.getData(topic_id: opposite)
- if group != nil || topic != nil {
- openEditorGroup(opposite: opposite)
- }
- }
- }
- UIApplication.shared.applicationIconBadgeNumber = 0
- UNUserNotificationCenter.current().removeAllDeliveredNotifications()
- completionHandler()
- }
-
- func openEditorPersonal(opposite: String) {
- let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
- editorPersonalVC.hidesBottomBarWhenPushed = true
- editorPersonalVC.unique_l_pin = opposite
- editorPersonalVC.fromNotification = true
- let onGoingCC = UserDefaults.standard.string(forKey: "onGoingCC") ?? ""
- if !onGoingCC.isEmpty {
- let compalintId = onGoingCC.components(separatedBy: ",")[2]
- let fPinCC = onGoingCC.isEmpty ? "" : onGoingCC.components(separatedBy: ",")[1]
- editorPersonalVC.isContactCenter = true
- editorPersonalVC.fPinContacCenter = fPinCC
- editorPersonalVC.complaintId = compalintId
- editorPersonalVC.onGoingCC = true
- editorPersonalVC.isRequestContactCenter = false
- }
- let navigationController = UINavigationController(rootViewController: editorPersonalVC)
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
-
- func openEditorGroup(opposite: String) {
- let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "editorGroupVC") as! EditorGroup
- editorGroupVC.hidesBottomBarWhenPushed = true
- editorGroupVC.unique_l_pin = opposite
- editorGroupVC.fromNotification = true
- let navigationController = UINavigationController(rootViewController: editorGroupVC)
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- if UIApplication.shared.visibleViewController?.navigationController != nil {
- UIApplication.shared.visibleViewController?.navigationController?.present(navigationController, animated: true, completion: nil)
- } else {
- UIApplication.shared.visibleViewController?.present(navigationController, animated: true, completion: nil)
- }
- }
- }
|