123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- //
- // 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.isShowForceSignIn = false
- APIS.connect(appName: Bundle.main.infoDictionary?["CFBundleName"] as! String , apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***", delegate: self, showButton: showButton, fromMAB: true) //23091CF494A11149F5A8FC8D17FF690DC69AE656F91B86070A11506ED24144F5(BPKH) //38747683290F62E9667A018F490396EAE47BC16ADECD85B7E865C733E6DBD6A2(OneApp)
- 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: String = SecureUserDefaults.shared.value(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 = CustomNavigationController(rootViewController: editorPersonalVC)
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = UIApplication.shared.visibleViewController?.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .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
- 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 = CustomNavigationController(rootViewController: editorGroupVC)
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = UIApplication.shared.visibleViewController?.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .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
- 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)
- }
- }
- }
|