AppDelegate.swift 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. import StreamShield
  11. @main
  12. class AppDelegate: UIResponder, UIApplicationDelegate {
  13. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  14. var showButton = false
  15. if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_FLOATING || PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_MIX {
  16. showButton = true
  17. }
  18. Nexilis.isShowForceSignIn = false
  19. APIS.connect(appName: Bundle.main.infoDictionary?["CFBundleName"] as! String , apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***", delegate: self, showButton: showButton, fromMAB: true) //23091CF494A11149F5A8FC8D17FF690DC69AE656F91B86070A11506ED24144F5(BPKH) //38747683290F62E9667A018F490396EAE47BC16ADECD85B7E865C733E6DBD6A2(OneApp)
  20. registerForPushNotifications()
  21. return true
  22. }
  23. // MARK: UISceneSession Lifecycle
  24. func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  25. // Called when a new scene session is being created.
  26. // Use this method to select a configuration to create the new scene with.
  27. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  28. }
  29. func applicationWillTerminate(_ application: UIApplication) {
  30. APIS.willTerminate()
  31. }
  32. private func registerForPushNotifications() {
  33. if #available(iOS 10.0, *) {
  34. let center = UNUserNotificationCenter.current()
  35. center.delegate = self
  36. center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
  37. if error == nil && granted {
  38. DispatchQueue.main.async {
  39. UIApplication.shared.registerForRemoteNotifications()
  40. }
  41. }
  42. }
  43. }
  44. else {
  45. UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
  46. UIApplication.shared.registerForRemoteNotifications()
  47. }
  48. }
  49. }
  50. extension AppDelegate: ConnectDelegate, UNUserNotificationCenterDelegate {
  51. func onSuccess(userId: String) {
  52. // print(#function, "userId: \(userId)")
  53. SecurityShield.check(appName: Bundle.main.infoDictionary?["CFBundleName"] as! String, apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***")
  54. }
  55. func onFailed(error: String) {
  56. //print(#function, "error: \(error)")
  57. }
  58. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  59. let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
  60. APIS.sendPushToken(deviceTokenString)
  61. }
  62. func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  63. //print(error)
  64. }
  65. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  66. APIS.showNotificationNexilis(userInfo)
  67. completionHandler(.newData)
  68. }
  69. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  70. completionHandler([.banner, .sound, .badge])
  71. }
  72. func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
  73. APIS.openNotificationNexilis(response)
  74. completionHandler()
  75. }
  76. }