gpt4 book ai didi

ios - Sinch 视频不想在 iOS 上运行 (Swift)

转载 作者:行者123 更新时间:2023-11-28 08:25:44 25 4
gpt4 key购买 nike

所以基本上我想在 iOS 应用程序中启用 Sinch Video。

出于测试目的,我创建了 SinchManaevger,它是单例的,并在 AppDelegate 中实例化了它:

class SinchManager: NSObject, SINClientDelegate, SINCallClientDelegate {

static let sharedInstance = SinchManager()

var client: SINClient?

func initSinchClientWithUserId(id: String) {
if client == nil {
if case .Authenticated(let currentUser, _) = SessionManager.sharedInstance.state.value {

self.client = Sinch.clientWithApplicationKey("xyz", applicationSecret: "xyz", environmentHost: "sandbox.sinch.com", userId: currentUser.username)
print("sinchClient")
print(client!)
self.client!.delegate = self
self.client!.setSupportCalling(true)
self.client!.enableManagedPushNotifications()
self.client!.start()
self.client!.startListeningOnActiveConnection()

}
}
}

func clientDidStart(client: SINClient!) {
print("clientDidStart")
self.client!.callClient().delegate = self
}

func clientDidStop(client: SINClient!) {
print("clientDidStop")
}

func clientDidFail(client: SINClient!, error: NSError!) {
print("clientDidFail")
}

func client(client: SINCallClient!, didReceiveIncomingCall call: SINCall!) {
print("didReceiveIncomingCall")
let sinchVC = SinchVC(username: currentUser.username)
let sinchNC = DNMMainNC(rootViewController: sinchVC)

sinchVC.call = call
}
}

我创建了 Sinch ViewController,它使用将被调用的用户名初始化:

class SinchVC: UIViewController, SINCallDelegate {

private let videoController = SinchManager.sharedInstance.client!.videoController()
private let audioController = SinchManager.sharedInstance.client!.audioController()
private let callClient: SINCallClient
private var call: SINCall!

let username: String

private var mainView: SinchView { return view as! SinchView }

override func loadView() {
view = SinchView()
}

init(username: String) {
self.username = username
self.callClient = SinchManager.sharedInstance.client!.callClient()

super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()


call.delegate = self

self.mainView.videoView.addSubview(self.videoController.localView())
self.videoController.localView().contentMode = .ScaleToFill

if self.call.direction == SINCallDirection.Incoming {
self.audioController.startPlayingSoundFile(self.pathForSound("incoming.wav") as String, loop: true)
}

if self.call.details.videoOffered {
print("video offered")
self.mainView.videoView.addSubview(self.videoController.localView())
self.videoController.localView().contentMode = .ScaleToFill
}

mainView.videoView.addSubview(self.videoController.localView())
mainView.answerButton.addTarget(self, action: #selector(answer), forControlEvents: .TouchUpInside)
mainView.declineButton.addTarget(self, action: #selector(decline), forControlEvents: .TouchUpInside)
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.audioController.enableSpeaker()
}

func pathForSound(string: String) -> NSString {
let nsSt = NSBundle.mainBundle().resourcePath! as NSString

return nsSt.stringByAppendingPathComponent(string)
}

func answer() {
call.answer()
}

func decline() {
call.hangup()
}

func callDidEstablish(call: SINCall!) {
print("callDidEstablish")
}

func callDidEnd(call: SINCall!) {
print("callDidEnd")
}

func callDidProgress(call: SINCall!) {
print("callDidProgress")
self.audioController.startPlayingSoundFile(self.pathForSound("ringback.wav") as String, loop: true)
}

func callDidAddVideoTrack(call: SINCall!) {
print("callDidAddVideoTrack")
mainView.videoView.addSubview(self.videoController.remoteView())
}


}

问题是当我尝试使用我的应用程序从我的应用程序调用其他手机时没有任何反应(didReceiveIncomingCall 委托(delegate)方法根本没有被调用)

如果我尝试从我的应用程序调用 SinchVideo 示例应用程序,则视频通话会正常启动。但是当我从 SinchVideo 应用程序调用我的应用程序时,我的应用程序没有任何反应。所以可能我忘记添加一些通知或在来电时告诉我的应用程序的东西。如果您能提供帮助,我将不胜感激。谢谢

编辑:我设法使 didReceiveIncomingCall 工作,但现在 call.answer 不工作。 (调用 call.answer 时没有任何反应,我看到我的电话正在响铃)

最佳答案

我不确定 DNMMainNC 在您收到来电时做了什么,

let sinchNC = DNMMainNC(rootViewController: sinchVC) What does DNMMainNC do?
sinchVC.call = call // private var?

但是从你的代码中设置一个私有(private) var 调用看起来有点奇怪,如果它不是公共(public)的或者有一个像你的 init 但有一个调用的构造函数

关于ios - Sinch 视频不想在 iOS 上运行 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40069072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com