1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // AppDelegate.swift
- // TestQmeraLite
- //
- // Created by Qindi on 29/11/21.
- //
- import UIKit
- import NexilisLite
- import NotificationBannerSwift
- import StreamShield
- @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 applicationWillTerminate(_ application: UIApplication) {
- APIS.willTerminate()
- }
-
- 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 && granted {
- 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)")
- SecurityShield.check(appName: Bundle.main.infoDictionary?["CFBundleName"] as! String, apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***")
- }
-
- func onFailed(error: String) {
- //print(#function, "error: \(error)")
- }
-
- func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
- let deviceTokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
- APIS.sendPushToken(deviceTokenString)
- }
-
- func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
- //print(error)
- }
-
- func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
- APIS.showNotificationNexilis(userInfo)
- completionHandler(.newData)
- }
- func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
- completionHandler([.banner, .sound, .badge])
- }
-
- func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
- APIS.openNotificationNexilis(response)
- completionHandler()
- }
- }
|