通过iOS中的电话呼叫日志进行voip呼叫

通过iOS中的电话呼叫日志进行voip呼叫,ios,callkit,Ios,Callkit,在我的Voip应用程序中,我使用callkit来接收来电。 使用以下方法: -(void)reportIncomingCall:(NSUUID*)UDID handle:(NSString*)handle{ 我可以在我的iPhone本机呼叫应用程序的呼叫历史记录中查看此传入呼叫的日志 我想从iPhone本机呼叫应用程序拨打外呼。我为WhatsApp、hangout等应用程序工作。但是,当我尝试从传入呼叫日志中呼叫用户时,无法唤醒我的应用程序 - (NSUUID *)reportOutgoing

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

-(void)reportIncomingCall:(NSUUID*)UDID handle:(NSString*)handle{
我可以在我的iPhone本机呼叫应用程序的呼叫历史记录中查看此传入呼叫的日志

我想从iPhone本机呼叫应用程序拨打外呼。我为WhatsApp、hangout等应用程序工作。但是,当我尝试从传入呼叫日志中呼叫用户时,无法唤醒我的应用程序

- (NSUUID *)reportOutgoingCallContactIdentifier:(NSString *)identifier destination:(NSString *)name telNumber:(NSString *)telnum 

基本上,您需要为您的目标创建意图扩展,以便处理来自本机呼叫历史记录的音频呼叫

在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)
    } 
}
然后,您需要为应用程序提供URL方案,以便在应用程序代理收到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
    }

}
您还需要在目标设置中注册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
}

基本上,您需要为您的目标创建意图扩展,以便处理来自本机呼叫历史记录的音频呼叫

在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)
    } 
}
然后,您需要为应用程序提供URL方案,以便在应用程序代理收到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
    }

}
您还需要在目标设置中注册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
}