-
Notifications
You must be signed in to change notification settings - Fork 6
/
AppDelegate.swift
75 lines (59 loc) · 3.25 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (c) 2011-2020, Zingaya, Inc. All rights reserved.
*/
import UIKit
import VoxImplantSDK
import CallKit
import Intents
let sharedClient: VIClient = VIClient(delegateQueue: DispatchQueue.main)
let sharedAuthService: AuthService = AuthService(sharedClient)
let sharedCallController: CXCallController = CXCallController(queue: .main)
let sharedCallManager: CallManager = CallManager(sharedClient, sharedAuthService)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CXCallObserverDelegate {
var window: UIWindow?
var callManager = sharedCallManager
var callController = sharedCallController
override init() {
super.init()
Logger.configure(appName: "AudioCallKit")
callController.callObserver.setDelegate(self, queue: .main)
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.isIdleTimerDisabled = true
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if callManager.hasManagedCall { return false }
guard let startCallIntent = userActivity.interaction?.intent else { return false }
var username: String?
if #available(iOS 13.0, *) { username = (startCallIntent as? INStartCallIntent)?.contacts?.first?.personHandle?.value }
else { username = (startCallIntent as? INStartAudioCallIntent)?.contacts?.first?.personHandle?.value }
guard username != nil else { return false }
let startOutgoingCall = CXStartCallAction(call: UUID(), handle: CXHandle(type: .generic, value: username!))
self.callController.requestTransaction(with: startOutgoingCall) { error in
guard let error = error else { return }
AlertHelper.showError(message: error.localizedDescription)
Log.e(error.localizedDescription)
}
return true
}
// MARK: - AppLifeCycle -
func applicationWillResignActive(_ application: UIApplication) {
(window?.rootViewController?.toppestViewController as? AppLifeCycleDelegate)?.applicationWillResignActive(application)
UIApplication.shared.isIdleTimerDisabled = false
}
func applicationDidEnterBackground(_ application: UIApplication) {
(window?.rootViewController?.toppestViewController as? AppLifeCycleDelegate)?.applicationDidEnterBackground(application)
}
func applicationWillEnterForeground(_ application: UIApplication) {
(window?.rootViewController?.toppestViewController as? AppLifeCycleDelegate)?.applicationWillEnterForeground(application)
}
func applicationDidBecomeActive(_ application: UIApplication) {
(window?.rootViewController?.toppestViewController as? AppLifeCycleDelegate)?.applicationDidBecomeActive(application)
}
// MARK: - CXCallObserverDelegate
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
(window?.rootViewController?.toppestViewController as? CXCallObserverDelegate)?.callObserver(callObserver, callChanged: call)
}
}