首页 > 解决方案 > 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() 有关,但我不知道我做错了什么。谢谢您的帮助。

标签: swiftaudiosinch

解决方案


推荐阅读