如何在Swift 4 iOS中将Callkit与Agora VOiP集成? [英] how to integrate Callkit with Agora VOiP in swift 4 iOS?

查看:340
本文介绍了如何在Swift 4 iOS中将Callkit与Agora VOiP集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Apple Callkit与Agora VOiP集成到Swift 4 iOS中。



请提出任何建议。

解决方案

要集成voip,必须同时使用callKit和PushKit。





在呼叫过渡期间,CallKit将用于显示本机呼叫屏幕和处理程序,而Pushkit将用于调用应用程序。



易于集成:-



在info.plist中启用后台模式并选中选项 App提供IP语音服务。
在视图控制器viewdidload /中用于实现CXProviderDelegate函数的任何类的任何init方法中导入Callkit。通过此操作,您将配置呼叫对象,何时报告呼叫,接受呼叫,拒绝呼叫等。



实现以下功能:

  func providerDidReset(_提供者:CXProvider){
}

func provider(_提供者:CXProvider,执行操作:CXAnswerCallAction ){
action.fulfill()
}

func provider(_ provider:CXProvider,执行动作:CXEndCallAction){
action.fulfill()
}

现在导入Pushkit并实现PKPushRegistryDelegate函数。



a。)像这样配置pushkit

 让注册表= PKPushRegistry(队列:无)
Registry.delegate =自我
Registry.desiredPushTypes = [PKPushType.voIP]

b。)实现pushkit令牌功能。您可能必须更新到服务器以传递voip推送通知

  func pushRegistry(_注册表:PKPushRegistry,didUpdate pushCredentials:PKPushCredentials,用于类型:PKPushType){
print(pushCredentials.token.map {字符串(format:%02.2hhx,$ 0)} .joined())
}

c。现在,当您收到传入通知时,请执行此功能

  func pushRegistry(_注册表:PKPushRegistry,didReceiveIncomingPushWith负载:PKPushPayload,类型为: PKPushType,完成:@escaping()-> Void){
let config = CXProviderConfiguration(localizedName: App name)
config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: any image name) !)

config.supportsVideo = true;
let provider = CXProvider(configuration:config)
provider.setDelegate(self,queue:nil)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type:。通用,值:呼叫者姓名)
update.hasVideo = true
provider.reportNewIncomingCall(with:UUID(),update:update,complete:{error in}}
}




  1. 转到开发人员门户并生成VoIP服务证书并安装

  2. 在功能下启用推送通知。

这是基本的代码。您将不得不添加案例以模拟来电和其他自定义。我希望这可以帮助您进一步发展。


I want to integrate apple Callkit with Agora VOiP in swift 4 iOS.

Please give any suggestions How can I do that.

解决方案

To integrate voip, you will have to use both, callKit and PushKit.

CallKit will be used to show native call screen and handlers during in call transition while Pushkit will be used to invoke app, when app is killed.

Its easy to integrate:-

Enable background modes in info.plist and check option "App provides Voice over IP services". Import Callkit in the viewcontroller viewdidload/ any init method of anyclass you would use to Implement CXProviderDelegate functions. Through this you will configure call objects, when to report in comming call, accept actions, reject action etc.

Implement the following functions:

func providerDidReset(_ provider: CXProvider) {
}

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    action.fulfill()
}

func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
    action.fulfill()
}

Now import Pushkit and implement PKPushRegistryDelegate functions.

a.)Configure pushkit like this

let registry = PKPushRegistry(queue: nil)
        registry.delegate = self
        registry.desiredPushTypes = [PKPushType.voIP]

b.) implement pushkit token function. You may have to update to server for delivering voip push notifications

 func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        print(pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined())
    }

c. Now when you receive incomming notification, implement this fuction

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        let config = CXProviderConfiguration(localizedName: "App name")
        config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "any image name")!)

        config.supportsVideo = true;
        let provider = CXProvider(configuration: config)
        provider.setDelegate(self, queue: nil)
        let update = CXCallUpdate()
        update.remoteHandle = CXHandle(type: .generic, value: "Caller name")
        update.hasVideo = true
        provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
    }

  1. Go to developer portal and generate VoIP Services certificate and install it.
  2. Enable push notifications under Capabilities.

This was a basic code over view. You will have to add cases to simulating incomming call and other customizations. I hope this will help you to move further.

这篇关于如何在Swift 4 iOS中将Callkit与Agora VOiP集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆