그래서 기본적으로 iOS 어플리케이션에서 Sinch Video를 사용하고 싶습니다.Sinch 비디오는 iOS (Swift)에서 작업하고 싶지 않습니다.
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())
}
}
을 내가 AppDelegate에 그것을 인스턴스화 할 및 싱글이다 SinchManaevger을 만든 테스트 목적으로
내 앱에서 다른 앱으로 전화를 걸려고하면 아무 문제가 발생하지 않습니다 (didReceiveIncomingCall 대리자 메소드가 전혀 호출되지 않음)
내 앱에서 SinchVideo 샘플 앱으로 전화를 걸면 화상 통화가 정상적으로 시작됩니다. 하지만 SinchVideo 앱에서 내 앱으로 전화하면 내 앱에서 아무 일도 일어나지 않습니다. 그래서 아마도 전화가 왔을 때 내 앱에 알리기 위해 알림이나 무언가를 추가하는 것을 잊어 버렸을 것입니다. 당신이 도와 주시면 아주 감사 할 것입니다. 감사합니다
편집 : didReceiveIncomingCall 작업을 관리하지만 지금은 call.answer is not working. (call.answer가 호출 될 때 아무 반응이 없습니다 그리고 난 내 휴대 전화 벨이 울리는 것을 참조)
tou는 대리자 메서드에서 call 속성을 구체적으로 참조해야합니다. 그렇지 않으면 작동하지 않습니다. –
코드를 편집 할 수 있습니까? 작업 솔루션의 완성도? 그것의 많은 작품에 내가 당신이 받아 들일 답변으로 게시물을 adn 할 수 있습니다. – cjensen
@cjensen 게시물을 수정했습니다. –