[英]make voip call from phone call log in iOS
In my Voip application I am using callkit to receive incoming call.在我的Voip应用程序中,我使用callkit来接收来电。 by using the below method:
通过使用以下方法:
-(void)reportIncomingCall:(NSUUID*)UDID handle:(NSString*)handle{
I can see the log of this incoming call in call history of my iPhone native call application.我可以在我的iPhone本机呼叫应用程序的呼叫历史记录中看到此来电的日志。
I wanted to make outgoing call from the iPhone native call application.我想从iPhone本机呼叫应用程序拨出电话。 I works for WhatsApp, hangout and etc applications.
我为WhatsApp、环聊等应用程序工作。 But, not able to wake up my application when I try calling the user from incoming call log.
但是,当我尝试从来电记录中呼叫用户时,无法唤醒我的应用程序。
- (NSUUID *)reportOutgoingCallContactIdentifier:(NSString *)identifier destination:(NSString *)name telNumber:(NSString *)telnum
Basically, you need to create Intents Extension for your target, in order to handle audio calls from native call history.基本上,您需要为您的目标创建 Intents Extension,以便处理来自本机呼叫历史记录的音频呼叫。
In Xcode:在 Xcode 中:
File -> New -> Target
文件 -> 新建 -> 目标
Select Intents Extension选择意图扩展
Here is the main class for the extension, this is how it should look like这是扩展的主类,它应该是这样的
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)
}
}
Than, you need to provide the URLScheme for your app in order to start a VoIP call when the app delegate receives the openURL然后,您需要为您的应用程序提供 URLScheme,以便在应用程序委托收到 openURL 时启动 VoIP 呼叫
Here is the extension for the NSUserActivity to help you detect the start call intent这是 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
}
}
You also need to register your URL scheme in your target settings:您还需要在目标设置中注册您的 URL 方案:
Xcode target settings, select Info card, and on the bottom URL Types, select + to add new type and give it a name, like VoIPCall
Xcode 目标设置,选择信息卡,然后在底部的 URL 类型上,选择 + 添加新类型并为其命名,例如
VoIPCall
In AppDelegate
override the following function在
AppDelegate
中覆盖以下函数
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
if userActivity.startCallHandle {
// START YOUR VOIP CALL HERE ----
}
return true
}
for swift 5 you should define continueuseractivity function to SceneDelegate.swift对于 swift 5 你应该定义 continueuseractivity 函数到 SceneDelegate.swift
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
let interaction = userActivity.interaction
if let startAudioCallIntent = interaction?.intent as? INStartAudioCallIntent{
let contact = startAudioCallIntent.contacts?.first
let contactHandle = contact?.personHandle
if let phoneNumber = contactHandle?.value {
print(phoneNumber)
//Your call logic
}
}
return
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.