Search code examples
iosvoipcallkit

Handling tel: links in voip app


Is there any method in iOS (CallKit? perhaps) where a VoIP app can register to handle tel: links? That way when a user selects a phone number (in safari for instance). They would be presented with two options to complete the call.


Solution

  • This is supported in iOS these days if you press and hold on a tel: link. It doesn't use the standard URI scheme system, though. CallKit seems to automatically register your app as a handler of tel: links if you declare support for phone calls, and the link is passed through the following event:

    import Intents
    
    protocol SupportedStartCallIntent {
      var contacts: [INPerson]? { get }
    }
    
    extension INStartAudioCallIntent: SupportedStartCallIntent {}
    extension INStartVideoCallIntent: SupportedStartCallIntent {}
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate, CXProviderDelegate {
    
      func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        let interaction = userActivity.interaction
        let startCallIntent = interaction?.intent as? SupportedStartCallIntent
        if let contact = startCallIntent?.contacts?.first?.displayName {
          // do what you want with 'contact'
        }
        return true
      }