Intercom & PushKit

Intercom integration

In order to integrate VoIP push messages into your application, you need to make the following changes.

Capabilities

Go to your project -> your target -> Signing & Capabilities -> + Capability.

Add Background Modes.

And Push Notifications.

Further it is necessary to mark the following points: Audio, Voice over IP, and Remote notifications.

Frameworks

You need to link CallKit and PushKit frameworks.

Code

In order to register VoIP device token on the backend, you need to pass it to SmartSpacesKit.


import UIKit
import PushKit
import SmartSpacesKit

@UIApplicationMain
class AppDelegate: UIResponder {

...

}

extension AppDelegate: UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ...

        registerVoIP()

        return true
    }

}

extension AppDelegate {

    func registerVoIP() {
        let voipRegistry = PKPushRegistry(queue: .main)
        voipRegistry.delegate = self
        voipRegistry.desiredPushTypes = [.voIP]
    }

}

extension AppDelegate: PKPushRegistryDelegate {

    func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        guard type == .voIP else {
            return
        }

        UserDeviceManager.shared().update(voipNotificationToken: pushCredentials.token)
        UserDeviceManager.shared().synchronize { error in
            if let error = error { print("[ERROR] Failed to synchronize user device manager: \(error)"); return }
            print("[DEBUG] Synchronizing user device manager finished")
        }
    }

    func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
        guard type == .voIP else {
            return
        }

        UserDeviceManager.shared().update(voipNotificationToken: nil)
        UserDeviceManager.shared().synchronize { error in
            if let error = error { print("[ERROR] Failed to synchronize user device manager: \(error)"); return }
            print("[DEBUG] Synchronizing user device manager finished")
        }
    }

    func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        // Handle your incoming push notification
        completion()
    }

}