处理电话:voip 应用程序中的链接

Handling tel: links in voip app

iOS(CallKit?也许)中是否有任何方法可以让 VoIP 应用程序注册以处理 tel: 链接?这样当用户选择 phone 号码时(例如在 safari 中)。他们将看到两个选项来完成通话。

今天 iOS 不存在这种能力。如果您对此感兴趣,我建议您在 Apple 的 Bug Report 网站上提交错误报告以请求它。

如果您按住 tel: link,目前 iOS 支持此功能。不过,它不使用标准的 URI 方案系统。如果您声明支持 phone 调用,CallKit 似乎会自动将您的应用注册为 tel: link 的处理程序,并且 link 通过以下事件传递:

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
  }