-
Notifications
You must be signed in to change notification settings - Fork 0
Receiving an incoming call
This guide will show you how to handle incoming calls and how to show the Kaleyra Video call UI in your app for the Kaleyra Video iOS SDK 4.0 version. If you are looking for the 3.x guide please take a look here
The steps required to handle an incoming call are the following:
- Connect the SDK
- Present the call user interface
Assuming the SDK is properly configured, you are required to connect it in order to start an outgoing call.
import UIKit
import KaleyraVideoSDK
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
var config = Config(appID: "My app id", region: .europe, environment: .sandbox)
config.callKit = .enabled(.init(icon: UIImage(named: "callkit-icon")))
config.voip = .automatic(listenForNotificationsInForeground: false)
do {
try KaleyraVideo.instance.configure(config)
try KaleyraVideo.instance.connect(userId: "USER ALIAS", provider: RestAccessTokenProvider())
} catch {
print("Could not configure the SDK because of \(error)")
}
return true
}
}
The last step needed in order to show an incoming call to the user is to present the call user interface. Let's pretend you have a view controller from which you want to present the call user interface; once the callPublisher emits a call object you can present the CallViewController associated with it:
import UIKit
import KaleyraVideoSDK
class MyViewController: UIViewController {
lazy var callWindow: CallWindow = .init(windowScene: view.window!.windowScene!)
override func viewDidLoad() {
super.viewDidLoad()
KaleyraVideo.instance.conference?.callPublisher.compactMap({ $0 }).receive(on: DispatchQueue.main).sink { [weak self] call in
self?.presentCall(call)
}.store(in: &subscriptions)
}
private func present(call: Call) {
let controller = CallViewController(call: call, configuration: .init())
controller.delegate = self
callWindow.makeKeyAndVisible()
callWindow.set(rootViewController: controller, animated: true)
}
}
extension MyViewController: CallViewControllerDelegate {
func callViewControllerDidFinish(_ controller: CallViewController) {
callWindow.set(rootViewController: nil, animated: true) { _ in
self.callWindow.isHidden = true
}
}
}
That's it! You don't have to do anything fancy, just present the call UI and you're good to go.
As a side note, if you have enabled CallKit support in the SDK, when an incoming call is received the native system UI will be always displayed even if your application is in foreground and active.
If you followed our guides regarding the call client you should have now a complete integration with our call system. If you haven't already, we suggest you to take a look at our sample apps (objective-c swift) to see how to handle incoming calls in a real world app. You should be now ready to move to more advanced topics, like enabling CallKit support in your app, or start integrating the VoIP notifications.
Looking for other platforms? Take a look at Android, Flutter, ReactNative, Ionic / Cordova. Anything unclear or inaccurate? Please let us know by submitting an Issue or write us here.