Videoala.io SDK for iOS
The Videola.io SDK for iOS and a sample project.
Pod 安装
要向您的应用程序添加 Videoala.io SDK for iOS,您需要 CocoaPods,它是一个 Objective-C 和 Swift 的依赖管理器。您可以通过以下命令安装 CocoaPods
$ gem install cocoapods
Podfile
要使用 CocoaPods 在 Xcode 项目中集成 Videoala.io SDK,请在您的 Podfile
中添加 VideolaSDK
pod
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'TargetName' do
pod 'VideolaSDK'
end
然后,运行以下命令
$ pod install
应用程序设置和使用
- 将
NSCameraUsageDescription
和NSMicrophoneUsageDescription
添加到应用程序的 Info.plist - 在目标 -> 编译设置 -> 启用位码中设置为 NO
- 在功能 -> 背景模式下选择“音频、AirPlay 和画中画”复选框
- 将
VideolaSDK
导入到AppDelegate
和您的ViewController
类
import VideolaSDK
- 在应用程序启动后注册您的 客户 ID
VideolaCallManager.setClientId("demo")
- 在
viewDidLoad
函数中为VideolaCallManager
设置委托
VideolaCallManager.setDelegate(self)
- 实现 Videola.io 通话界面的创建
VideolaCallManager.callCode(code, videoCall: true, textChat: true, on: self) { (creationError) in
if creationError != CallInitError.none {
// show error here
}
}
- 实现令牌签名的委托函数。注意:以下示例实现的签名端点由 Videola.io 提供,并且仅适用于
demo
客户端 ID
func request(toSignApiAuthToken token: String!) {
guard let url = URL(string: "https://demo.videola.io/signer") else {
VideolaCallManager.authorize(nil)
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("text/plain", forHTTPHeaderField: "Content-Type")
request.httpBody = token.data(using: String.Encoding.utf8)
session.dataTask(with: request, completionHandler: { (data, response, error) in
if let data = data, let signedToken = String(data: data, encoding: String.Encoding.utf8) {
VideolaCallManager.authorize(signedToken)
} else {
VideolaCallManager.authorize(nil)
}
}).resume()
}
- 实现其他有用的委托函数
func callEstablished() {}
func callEnd(_ reason: VideolaCallEndReason) {}
func recordingStateChanged() {}
func recordingFilename(_ filename: String!) {}
- 构建并运行您的应用程序。