swift - Swift 中的基本 Sinch 示例 - 但没有声音
问题描述
首先感谢您阅读我的台词。对于一个想法,我目前正试图深入 Swift 世界(我只有非常基本的编程知识 - 没有 Objective C 知识)。
我尝试设置以下几行以在 Sinch 中创建一个非常基本的应用程序到应用程序示例。在我的代码之后,我让你知道问题所在。
import UIKit
import Sinch
var appKey = "APP_KEY_FROM_MY_ACCOUNT"
var hostname = "clientapi.sinch.com"
var secret = "SECRET_FROM_MY_ACCOUNT"
class CViewController: UIViewController, SINCallClientDelegate, SINCallDelegate, SINClientDelegate {
var client: SINClient?
var call: SINCall?
var audio: SINAudioController?
//Text field in the main storyboard
@IBOutlet weak var userNameSepp: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.initSinchClient()
}
//initialize and start the client as a fixed "userA"
func initSinchClient() {
client = Sinch.client(withApplicationKey: appKey, applicationSecret: secret, environmentHost: hostname, userId: "userB")
client?.call().delegate = self
client?.delegate = self
client?.startListeningOnActiveConnection()
client?.setSupportCalling(true)
client?.start()
}
//Did the Client start?
func clientDidStart(_ client: SINClient!) {
print("Hello")
}
//Did the Client fail?
func clientDidFail(_ client: SINClient!, error: Error!) {
print("Good Bye")
}
//Call Button in the main.storyboard ... if call==nil do the call ... else hangup and set call to nil
//the background color changes are my "debugging" :D
@IBAction func callSepp(_ sender: Any) {
if call == nil{
call = client?.call()?.callUser(withId: userNameSepp.text)
//for testing I change to callPhoneNumber("+46000000000").
// the phone call progresses (but I hear nothing),
// the phonecall gets established (but I hear nothing)
// and the phonecall gets ended (but of course I hear nothing)
self.view.backgroundColor = UIColor.red
call?.delegate = self
audio = client?.audioController()
}
else{
call?.hangup()
self.view.backgroundColor = UIColor.blue
call = nil
}
}
func callDidProgress(_ call: SINCall?) {
self.view.backgroundColor = UIColor.green
client?.audioController().startPlayingSoundFile("/LONG_PATH/ringback.wav", loop: true)
print("Call in Progress")
}
//I know that this works but I don't hear anything
func callDidEstablish(_ call: SINCall!) {
client?.audioController().stopPlayingSoundFile()
print("Call did Establish")
}
func callDidEnd(_ call: SINCall!) {
print("Call did end")
}
// this works fine
@IBAction func hangUpSepp(_ sender: Any) {
call?.hangup()
self.view.backgroundColor = UIColor.red
call = nil
}
// i work in a "sub view controller" - so i navigate here back to the main view controller
@IBAction func goBackMain(_ sender: Any) {
call?.hangup()
dismiss(animated: true, completion: nil)
client?.stopListeningOnActiveConnection()
client?.terminateGracefully()
client = nil
}
}
所以我可以拨打我的私人电话号码,或者如果我更改为 callUser,我可以拨打另一个应用程序,但我什么也听不到。我想念什么?它必须与 SINAudioController 和客户端的方法 audioController() 有关,但我不知道我做错了什么。谢谢您的帮助。
解决方案
推荐阅读
- javascript - 剑道网格自动适应除特定列之外的列宽
- amazon-web-services - 降低从 S3 存储桶(多个存储桶)到我们的数据中心的传输费用
- javascript - Mongodb不尊重唯一的部分索引
- python - 维护一个视图的简单数据库?
- javascript - 映射深层嵌套对象数组 JSON 文件
- list - 我正在努力理解如何在 Haskell 中读取 concat
- javascript - 在 D3 中,如何在可缩放树状图中选择当前节点的特定子元素?
- python - 我怎么知道一个属性在哪里被调用?Python
- c - 如何解析 AT 命令响应和 C 输出中的字段之一
- javascript - REGEXP帮助需要渲染404路径