从iOS的电话记录中拨打voip电话

问题描述 投票:1回答:1

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

-(void)reportIncomingCall:(NSUUID*)UDID handle:(NSString*)handle{

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

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

- (NSUUID *)reportOutgoingCallContactIdentifier:(NSString *)identifier destination:(NSString *)name telNumber:(NSString *)telnum 
ios callkit
1个回答
3
投票

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

在Xcode中:

文件 - >新建 - >目标

选择Intents Extension

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

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)
}

}

比,您需要为您的应用提供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
    }

}

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

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

在AppDeledate中覆盖以下函数

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

    if userActivity.startCallHandle {
        // START YOUR VOIP CALL HERE ----
    }
    return true
}
© www.soinside.com 2019 - 2024. All rights reserved.