2016-10-16 2 views
0

그래서 기본적으로 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가 호출 될 때 아무 반응이 없습니다 그리고 난 내 휴대 전화 벨이 울리는 것을 참조)

+1

tou는 대리자 메서드에서 call 속성을 구체적으로 참조해야합니다. 그렇지 않으면 작동하지 않습니다. –

+0

코드를 편집 할 수 있습니까? 작업 솔루션의 완성도? 그것의 많은 작품에 내가 당신이 받아 들일 답변으로 게시물을 adn 할 수 있습니다. – cjensen

+1

@cjensen 게시물을 수정했습니다. –

답변

0

내가 DNMMainNC이했다를 받게되며 수신 전화에 무엇 확실하지 않다,

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

을하지만 그것의 외모 종류의 이상한 코드에서 private var 호출을 public으로 설정하거나 init과 같은 생성자를 호출해야합니다.

+0

이 글을 읽으면 http://stackoverflow.com/questions/26087447/private-var-is-accesible-from-outside-the-class 나를 조금 화나게 할 것입니다. 클래스보다는 개인 위치를 물리적 위치로 제한하십시오. – cjensen

관련 문제