从 iOS 中的电话登录进行 voip 通话

ios*_*per 1 ios callkit

在我的Voip应用程序中,我使用callkit来接听来电。通过使用以下方法:

-(void)reportIncomingCall:(NSUUID*)UDID handle:(NSString*)handle{
Run Code Online (Sandbox Code Playgroud)

我可以在iPhone本机通话应用程序的通话记录中看到此来电的日志。

我想从iPhone本机呼叫应用程序拨出电话。我为WhatsApp、环聊等应用程序工作。但是,当我尝试从来电记录呼叫用户时无法唤醒我的应用程序。

- (NSUUID *)reportOutgoingCallContactIdentifier:(NSString *)identifier destination:(NSString *)name telNumber:(NSString *)telnum 
Run Code Online (Sandbox Code Playgroud)

Mik*_*iki 5

基本上,您需要为目标创建 Intents 扩展,以便处理来自本机通话记录的音频通话。

在Xcode中:

文件 -> 新建 -> 目标

选择意图扩展

这是扩展的主类,它应该是这样的

class IntentHandler: INExtension, INStartAudioCallIntentHandling {

func handle(intent: INStartAudioCallIntent, completion: @escaping (INStartAudioCallIntentResponse) -> Void) {
    let response: INStartAudioCallIntentResponse
    defer {
        completion(response)
    }

    // Ensure there is a person handle
    guard intent.contacts?.first?.personHandle != nil else {
        response = INStartAudioCallIntentResponse(code: .failure, userActivity: nil)
        return
    }

    let userActivity = NSUserActivity(activityType: String(describing: INStartAudioCallIntent.self))

    response = INStartAudioCallIntentResponse(code: .continueInApp, userActivity: userActivity)
    } 
}
Run Code Online (Sandbox Code Playgroud)

然后,您需要为您的应用程序提供 URLScheme,以便在应用程序委托收到 openURL 时启动 VoIP 呼叫

这是 NSUserActivity 的扩展,可帮助您检测开始呼叫意图

import Intents

@available(iOS 10.0, *)
protocol SupportedStartCallIntent {
    var contacts: [INPerson]? { get }
}

@available(iOS 10.0, *)
extension INStartAudioCallIntent: SupportedStartCallIntent {}

@available(iOS 10.0, *)
extension NSUserActivity {

    var startCallHandle: String? {
        guard let startCallIntent = interaction?.intent as? SupportedStartCallIntent else {
            return nil
        }
        return startCallIntent.contacts?.first?.personHandle?.value
    }

}
Run Code Online (Sandbox Code Playgroud)

您还需要在目标设置中注册您的 URL 方案:

Xcode 目标设置,选择信息卡,然后在底部的 URL 类型上,选择 + 添加新类型并为其命名,例如 VoIPCall

AppDelegate覆盖以下功能

func application(_ application: UIApplication,
               continue userActivity: NSUserActivity,
               restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    if userActivity.startCallHandle {
        // START YOUR VOIP CALL HERE ----
    }
    return true
}
Run Code Online (Sandbox Code Playgroud)