Sinch video doen';我不想在iOS上工作(Swift)
所以基本上我想在iOS应用程序中启用Sinch视频 出于测试目的,我创建了Singhmanaevger,它是singleton,我在AppDelegate中安装它:Sinch video doen';我不想在iOS上工作(Swift),ios,swift,sinch,Ios,Swift,Sinch,所以基本上我想在iOS应用程序中启用Sinch视频 出于测试目的,我创建了Singhmanaevger,它是singleton,我在AppDelegate中安装它: class SinchManager: NSObject, SINClientDelegate, SINCallClientDelegate { static let sharedInstance = SinchManager() var client: SINClient? func initSinc
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委托方法根本没有被调用)
如果我尝试从我的应用程序呼叫SinchVideo示例应用程序,则视频呼叫将正常启动。但当我从SinchVideo应用程序调用我的应用程序时,我的应用程序中什么都没有发生。所以我可能忘了添加一些通知或在来电时告诉我的应用程序的东西。如果你能帮忙,我将非常感激。谢谢
编辑:我设法使didReceiveIncomingCall工作,但现在call.answer不工作。(当call.answer被呼叫时,不会发生任何事情,我看到我的手机正在响)我不确定DNMMainNC在您的did接收来电时做了什么
let sinchNC = DNMMainNC(rootViewController: sinchVC) What does DNMMainNC do?
sinchVC.call = call // private var?
但是从代码中设置一个私有var调用看起来有点奇怪,如果不是公共的,或者有一个类似init的构造函数,但是有一个调用我不确定DNMMainNC在did Receive传入调用中做了什么
let sinchNC = DNMMainNC(rootViewController: sinchVC) What does DNMMainNC do?
sinchVC.call = call // private var?
但是从代码中设置私有var调用看起来有点奇怪,如果不是公共的,或者像init一样有构造函数,但是调用时tou必须特别引用委托方法中的call属性,否则它将不起作用-solved您可以编辑代码以确保工作解决方案的完整性吗?如果工作太多,我可以做,并将其作为您接受的答案发布。@cjensen我已经编辑了这篇文章。我下面的答案有帮助吗?如果是,请您将其标记为已回答。Thankstou必须特别引用委托方法中的call属性,否则它将不起作用-Solved您可以编辑代码以确保与工作解决方案的完整性吗?如果工作太多,我可以做,并将其作为您接受的答案发布。@cjensen我已经编辑了这篇文章。我下面的答案有帮助吗?如果是的话,你能把它标记为已回答吗?谢谢阅读这篇文章让我有点不安,为什么你要把private限制在物理位置而不是类。阅读这篇文章让我有点不安,为什么你要把private限制在物理位置而不是类。