Sinch is not supporting video call in swift - ios

here is my code. I covert this code from objective c to swift from the sinch test` Giving the Objective-C part might be interesting to help but it's not supporting video call. when i accept the call audio is working fine. but video is not sending to the other device. please help me out if any one has the sample code for swift then send or try to fix it with this code.. thanks
// MARK: - Load
override func viewDidLoad() {
super.viewDidLoad()
if call?.direction == SINCallDirection.incoming {
self.callStateLabel.text = ""
self.showButtons(EButtonsBar.kButtonsAnswerDecline)
//audioController().startPlayingSoundFile(path(forSound: "incoming.wav"), loop: true)
} else {
self.callStateLabel.text = "calling..."
self.showButtons(EButtonsBar.kButtonsHangup)
}
if (call?.details.isVideoOffered)! {
localVideoView.addSubview(videoController().localView())
localVideoFullscreenGestureRecognizer.require(toFail: switchCameraGestureRecognizer)
videoController().localView().addGestureRecognizer(localVideoFullscreenGestureRecognizer)
videoController().remoteView().addGestureRecognizer(remoteVideoFullscreenGestureRecognizer)
}
}
#IBAction func accept(sender: AnyObject) {
call?.answer()
}
#IBAction func decline(sender: AnyObject) {
call?.hangup()
dismiss(animated: true, completion: nil)
}
#IBAction func hangup(sender: AnyObject) {
call?.hangup()
dismiss(animated: true, completion: nil)
}
func audioController() -> SINAudioController{
return Global.client.audioController()
}
func videoController() -> SINVideoController {
return Global.client.videoController()
}

Add 2 Views in your view controller. One is for local video view and another one is for remote video video. Set it outlets to view controller. I have a working audio call example and i just add this things to my call view controller.
func videoController() -> SINVideoController {
return appDeletgate.client.videoController()
}
In viewdidload check for if video is offered by call.
if call.details.isVideoOffered {
localVideoView.addSubview(videoController().localView())
//localVideoFullscreenGestureRecognizer.require(toFail: switchCameraGestureRecognizer)
//videoController().localView().addGestureRecognizer(localVideoFullscreenGestureRecognizer)
//videoController().remoteView().addGestureRecognizer(remoteVideoFullscreenGestureRecognizer)
}
Add this method to add remote video in view.
func callDidAddVideoTrack(_ call: SINCall?) {
remoteVideoView.addSubview(videoController().remoteView())
}
Also make sure you add this 2 keys into info.plist
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) need to access your camera for video call.</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses the Microphone for calling</string>
And this is finally how i call it.
let call: SINCall? = self.callClient().callUserVideo(withId: recipientName) //self.callClient().callUser(withId: recipientName)
let callVC = mainStoryBoard.instantiateViewController(withIdentifier: "CallVC") as! CallVC
callVC.call = call
self.navigationController?.pushViewController(callVC, animated: true)

Related

Microblink : Scanning both side of ID card

I am trying to scan both side of national card with mircoblink, based on their documentation for scanning both side you have to use MBDocumentVerificationOverlayViewController for controller and MBBlinkIdCombinedRecognizer for recognizer. but only my front side scanning works well.
I am using demo serial key, I don't know is it related to to my serial key or not.
here is my code:
/** Create BlinkID recognizer */
blinkIdRecognizer = MBBlinkIdCombinedRecognizer()
/** Create BlinkID settings */
let settings : MBDocumentVerificationOverlaySettings = MBDocumentVerificationOverlaySettings()
/** Crate recognizer collection */
let recognizerCollection : MBRecognizerCollection = MBRecognizerCollection(recognizers: [blinkIdRecognizer!])
/** Create your overlay view controller */
let documentOverlayViewController : MBDocumentVerificationOverlayViewController = MBDocumentVerificationOverlayViewController(settings: settings, recognizerCollection: recognizerCollection, delegate: self)
/** Create recognizer view controller with wanted overlay view controller */
let recognizerRunneViewController : UIViewController = MBViewControllerFactory.recognizerRunnerViewController(withOverlayViewController: documentOverlayViewController)
/** Present the recognizer runner view controller. You can use other presentation methods as well (instead of presentViewController) */
present(recognizerRunneViewController, animated: true, completion: nil)
This is my delegate code:
extension MyVC: MBDocumentVerificationOverlayViewControllerDelegate {
func documentVerificationOverlayViewControllerDidFinishScanningFirstSide(_ documentVerificationOverlayViewController: MBDocumentVerificationOverlayViewController) {
print("First Side Scanned")
}
func documentVerificationOverlayViewControllerDidFinishScanning(_ documentVerificationOverlayViewController: MBDocumentVerificationOverlayViewController, state: MBRecognizerResultState) {
if (self.blinkIdRecognizer?.combinedResult.resultState == MBRecognizerResultState.valid) {
guard let result = blinkIdRecognizer?.combinedResult else {
return
}
DispatchQueue.main.async {
if self.blinkIdRecognizer?.combinedResult.scanningFirstSideDone == true {
} else {
documentVerificationOverlayViewController.dismiss(animated: true, completion: nil)
}
}
}
}
func documentVerificationOverlayViewControllerDidTapClose(_ documentVerificationOverlayViewController: MBDocumentVerificationOverlayViewController) {
self.dismiss(animated: true, completion: nil)
}
}
And scanning first side delegate never get called, but I see response in DidFinish
thanks for any help
What version of the SDK are you using?
In version 5.2, we have added scanning for both the front and backside of the German ID.
You can download the latest release here:
https://github.com/BlinkID/blinkid-ios/releases
Can you please test it now and let us know if that worked?
Milan
Last time I've worked with microblink was over a year ago but if I recall correctly documentVerificationOverlayViewControllerDidFinishScanningFirstSide is only available for the supported id cards.
If you're scanning an ID card from another country you'll need to implement that yourself.
For example:
func documentVerificationOverlayViewControllerDidFinishScanning(_ documentVerificationOverlayViewController: MBDocumentVerificationOverlayViewController, state: MBRecognizerResultState) {
if step == .first {
// Present another ViewController for the back
showBackScanner()
} else {
processData()
}
}

Failing to use MPMediaPickerController

I am trying to use MPMediaPickerController for the first time, in an iOS application.
Here is the relevant code:
......
import MediaPlayer
class ViewController: UIViewController,...,MPMediaPickerControllerDelegate {
......
var mediPic_VC:MPMediaPickerController!
......
#objc func fireMediaPicker() {
if mediPic_VC == nil {
mediPic_VC = MPMediaPickerController(mediaTypes: .anyAudio)
//mediPic_VC = MPMediaPickerController(mediaTypes: .music)
mediPic_VC.delegate = self
}
self.present(mediPic_VC, animated: true, completion: nil)
}
......
// MPMediaPickerControllerDelegate protocol implementation.
func mediaPicker(_ mediaPicker: MPMediaPickerController,
didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
print(#function)
}
func mediaPickerDidCancel(_ mediaPicker: MPMediaPickerController) {
print(#function)
}
// End of MPMediaPickerControllerDelegate protocol implementation.
......
}
As one can see I have a function (fireMediaPicker) to bring up the MPMediaPickerController.
But when I run it, the app shows nothing more than a white screen and the debugging console displays the message:
mediaPickerDidCancel(_:)
proving that the function mediaPickerDidCancel of the MPMediaPickerControllerDelegate protocol has been called.
Instead of the white screen I was expecting to see a list of audio items to choose from.
Beside, I have no idea why mediaPickerDidCancel is called.
What did I miss in the way I am trying to use MPMediaPickerController?
Add these to your plist:
<key>NSAppleMusicUsageDescription</key>
<string>your own string</string>

how can I handle properly the behavior of camera in my Swift app?

In my swift app I'm allowing users to take photos.
For that purpose I've decided to use CameraManager from here: https://github.com/imaginary-cloud/CameraManager
When user opens my app, he sees a button - when he presses it, the camera view appears and he can take a photo. He also can dismiss the camera view and later on, at some point, press the button one more time to open camera view again.
If I understand it correctly from the plugin docs, I need to add a camera view to my view during first usage, then - in case of dismiss - invoke stopCaptureSession(), and during every next usage call resumeCaptureSession().
Currently in my swift code I have three methods:
let cameraManager = CameraManager()
fileprivate func addCameraToView()
{
cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: CameraOutputMode.stillImage)
}
fileprivate func stopCaptureSession() {
cameraManager.stopCaptureSession()
}
fileprivate func resumeCaptreSession() {
cameraManager.resumeCaptureSession()
}
The IBAction for the button has the following code:
let currentCameraState = cameraManager.currentCameraStatus()
if currentCameraState == .notDetermined {
cameraManager.askUserForCameraPermission({ permissionGranted in
if permissionGranted {
self.resumeCaptreSession()
}
})
} else if (currentCameraState == .ready) {
self.resumeCaptreSession()
} else {
print("we do not have access to camera")
}
and in the IBAction for the dismiss button I had:
print("cancelling camera")
stopCaptureSession()
To make it work properly, I need to call addCameraToView() somewhere earlier - until now I was adding it in viewDidLoad, but I realized that I cannot do that because while doing so - the camera stays active until user presses the dismiss button.
So I thought about changing my code in IBAction for the camera button and add a camera from there. However, I have to add it only in case it wasn't add before - in the other case I need to call resumeCaptureSession().
The problem is that in CameraManager the function responsible for adding camera to the view is declared like this:
open func addPreviewLayerToView(_ view: UIView, newCameraOutputMode: CameraOutputMode) -> CameraState {
return addLayerPreviewToView(view, newCameraOutputMode: newCameraOutputMode, completion: nil)
}
open func addLayerPreviewToView(_ view: UIView, newCameraOutputMode: CameraOutputMode, completion: ((Void) -> Void)?) -> CameraState {
if _canLoadCamera() {
if let _ = embeddingView {
if let validPreviewLayer = previewLayer {
validPreviewLayer.removeFromSuperlayer()
}
}
if cameraIsSetup {
_addPreviewLayerToView(view)
cameraOutputMode = newCameraOutputMode
if let validCompletion = completion {
validCompletion()
}
} else {
_setupCamera({ Void -> Void in
self._addPreviewLayerToView(view)
self.cameraOutputMode = newCameraOutputMode
if let validCompletion = completion {
validCompletion()
}
})
}
}
return _checkIfCameraIsAvailable()
}
and resumeCaptureSession() is defined like this:
open func resumeCaptureSession() {
if let validCaptureSession = captureSession {
if !validCaptureSession.isRunning && cameraIsSetup {
validCaptureSession.startRunning()
_startFollowingDeviceOrientation()
}
} else {
if _canLoadCamera() {
if cameraIsSetup {
stopAndRemoveCaptureSession()
}
_setupCamera({Void -> Void in
if let validEmbeddingView = self.embeddingView {
self._addPreviewLayerToView(validEmbeddingView)
}
self._startFollowingDeviceOrientation()
})
}
}
}
So my question is - when user opens camera view, how can I check if camera was added to the view before, and if it was added - call resumeCaptureSession(), otherwise do not call it and just leave it with calling addCameraToView?

XCode8 Swift3 - Problems with open contact list and retrieve data by click

Currently I'm developing my first iOS App and I'm a little slow and rude about the code (it's so weird and different from java) and, if this was the only problem, with the new update, Xcode is making my code insane. I think I solved most of the issues but...
Before, on one of the screens, the app opened a the address book and let the user click on one; when the clicked was done, the contact list close and data from that contact was retrieved to the controller. Now, if the user click on a contact, more info is displayed but any information come out of the console log.
I try everything I find on net and I'm not sure why is not working.
Before, I use Addressbook (or something like that) but I already tried with CNContact.
This is the Button code
#IBAction func addNewContactOnClick(_ sender: AnyObject) {
let peoplePicker = CNContactPickerViewController()
peoplePicker.delegate = self
self.present(peoplePicker, animated: true, completion: nil)
}
CNContactPickerDelegate methods
func contactPicker(picker: CNContactPickerViewController, didSelectContacts contacts: [CNContact]){
contacts.forEach { contact in
for number in contact.phoneNumbers {
let phoneNumber = number.value as! CNPhoneNumber
print("number is = \(phoneNumber)")
}
}
}
func contactPickerDidCancel(picker: CNContactPickerViewController) {
print("Cancel Contact Picker")
}
Methods of CNContactPickerDelegate is changed in Swift 3 like below.
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
//your code
}
func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
//your code
}
For other methods of CNContactPickerDelegate check Apple Documentation.

CNContactViewController Cancel Button Not Working

I'm trying to use the built-in new contact UI and am getting unexpected behavior with the cancel button. The code below works and calls up the new contact screen but the cancel button will only clear the screen entries not cancel out of the new contact screen. In the built in contacts app hitting cancel returns to the contact list screen. I would like the cancel button to close out the window.
#IBAction func newTwo(sender: AnyObject) {
AppDelegate.getAppDelegate().requestForAccess { (accessGranted) -> Void in
if accessGranted {
let npvc = CNContactViewController(forNewContact: nil)
npvc.delegate = self
self.navigationController?.pushViewController(npvc, animated: true)
}
}
}
did you implement CNContactViewControllerDelegate methods?
Here's a link to documentation
for example:
func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
self.dismissViewControllerAnimated(true, completion: nil)
}
It worked for me using the following code:
Swift 3
func contactViewController(_ vc: CNContactViewController, didCompleteWith con: CNContact?) {
vc.dismiss(animated: true)
}
Also I changed the way I was calling the controller:
Instead of:
self.navigationController?.pushViewController(contactViewController, animated: true)
the solution was:
self.present(UINavigationController(rootViewController: contactViewController), animated:true)
I found the solution using the example code Programming-iOS-Book-Examples written by Matt Neuburg:
Better way to do the dismissing would be to check if the contact is nil and then dismiss it. The dismiss doesn't work if you've pushed the view controller from a navigation controller. You might have to do the following:
func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
if let contactCreated = contact
{
}
else
{
_ = self.navigationController?.popViewController(animated: true)
}
}

Resources