123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //
- // AppDelegate.swift
- // TestQmeraLite
- //
- // Created by Qindi on 29/11/21.
- //
- import UIKit
- import NexilisLite
- import NotificationBannerSwift
- import StreamShield
- import PushKit
- @main
- class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {
- var appName = Bundle.main.infoDictionary?["CFBundleName"] as! String
- var apikey = "***REPLACE***WITH***YOUR***ACCOUNT***"
- 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: appName , apiKey: apikey, delegate: self, showButton: showButton, fromMAB: true) //23091CF494A11149F5A8FC8D17FF690DC69AE656F91B86070A11506ED24144F5(BPKH) //38747683290F62E9667A018F490396EAE47BC16ADECD85B7E865C733E6DBD6A2(OneApp)
- registerForPushNotifications()
- registerForVoIPPushNotifications()
- 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()
- APIS.enterBackground()
- }
-
- 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()
- }
- }
-
- func registerForVoIPPushNotifications() {
- let mainQueue = DispatchQueue.main
- let voipRegistry = PKPushRegistry(queue: mainQueue)
- voipRegistry.delegate = self
- voipRegistry.desiredPushTypes = [.voIP]
- }
-
- func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
- let deviceToken = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
- APIS.sendPushToken(deviceToken, isCall: true)
- }
-
- func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
- print("Received VoIP Push: \(payload.dictionaryPayload)")
- completion()
- }
- }
- extension AppDelegate: ConnectDelegate, UNUserNotificationCenterDelegate {
-
- func onSuccess(userId: String) {
- // print(#function, "userId: \(userId)")
- SecurityShield.check(appName: appName, apiKey: apikey)
- }
-
- 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()
- }
- }
|