BlinkID / blinkid-xamarin

ID scanning SDK, wrapped for cross-platform apps built with Xamarin.
https://microblink.com/blinkid
50 stars 24 forks source link

Finished Scanning Handler #2

Closed matthewjcooper closed 8 years ago

matthewjcooper commented 8 years ago

Is there any events that i can manually add to the iOS Binding export for the custom delegate, that would let me know when the scanning operation is completed.

Right now at the end of the DidOutputResults i'm saving the data I received from the scan to a sqlite db and then trying to segue to another view controller, and the code executes but i think the scan overlay view controller is then cancelling that segue or something, because it just returns me to the current view controller that had the button click event that called BlinkId.Instance().Scan().

Any guidance for this is appreciated.

dgust6 commented 8 years ago

From which view controller are you trying to segue to another view controller? If you are transitioning to a new view controller from the one that called BlinkId.Instance().Scan() that might cause this behaviour. If you want to transition from the view controller that does the scanning, we could expose it in the next release.

matthewjcooper commented 8 years ago

Yes. A summary of my scenerio is below:

Fist View Controller Button called Scan Drivers License When clicked calls BlinkId.Instance().Scan(); You then put your DL behind the camera and it scans. DidOutputResults fires, and I save values to db Need to then segue to Second View Controller

Second View Controller OnViewDidLoad pulls values from db and updates controls to edit.

From: Pickles112358 notifications@github.com<mailto:notifications@github.com> Reply-To: BlinkID/blinkid-xamarin reply@reply.github.com<mailto:reply@reply.github.com> Date: Wednesday, June 29, 2016 at 11:20 AM To: BlinkID/blinkid-xamarin blinkid-xamarin@noreply.github.com<mailto:blinkid-xamarin@noreply.github.com> Cc: Matthew Cooper matthewc@atiba.com<mailto:matthewc@atiba.com>, Author author@noreply.github.com<mailto:author@noreply.github.com> Subject: Re: [BlinkID/blinkid-xamarin] Finished Scanning Handler (#2)

From which view controller are you trying to segue to another view controller? If you are transitioning to a new view controller from the one that called BlinkId.Instance().Scan() that might cause this behaviour. If you want to transition from the view controller that does the scanning, we could expose it in the next release.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BlinkID/blinkid-xamarin/issues/2#issuecomment-229409170, or mute the threadhttps://github.com/notifications/unsubscribe/ABXggeUDn7kWYNHbIdfkPWJnDweqD0lCks5qQptXgaJpZM4JBTmX.

Matthew Cooper

6153893357x127 matthewc@atiba.com

ATIBA | ENGAGING SOLUTIONS Network Services | Custom Software | Website Development | Mobile Apps Interactive Marketing | Microsoft Certified Partner | Dell GeoPartner www.atiba.comhttp://www.atiba.com

dgust6 commented 8 years ago

Yes, the issue here is that when calling a Scan() method, we present our scanning view controller internally. So, when you try to segue, you are not transitioning from scanning view controller (current topmost view controller) but from view controller that had the button. In the next release we will expose the scanning view controller so you can transition from it.

In the meantime you can access it from the class that called the Scan() method like this:

this.PresentedViewController

documentation available here: https://developer.xamarin.com/api/property/MonoTouch.UIKit.UIViewController.PresentedViewController/

You could also look at this thread for fetching the topmost view controller: https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service

Kind regards, Dino

matthewjcooper commented 8 years ago

I’m passing a reference to the calling view controller in the constructor of my CustomDelegate and then calling perform segue on it, and it won’t work. I’m also calling perform segue after calling scan from the same event and it’s not working. It’s like the scan view controller is cancelling any segue transitions. Below is my code:

using System;

using UIKit; using Foundation; using System.Linq;

using System.Diagnostics;

using MicroBlink; using HealthHere.Kiosk.Models; using SQLite; using System.Globalization;

namespace HealthHere.Kiosk {

public partial class ViewController : UIViewController
{

    public bool DidScan;

    public ViewController(IntPtr handle) : base(handle)
    {
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        //DemographicView.Hidden = true;

        CustomDelegate customDelegate = new CustomDelegate(this);

        BlinkID.Instance().LicenseKey = "xxxxxxxxxx";
        BlinkID.Instance().Delegate = customDelegate;

    }

    partial void ScanDLButton_TouchUpInside(UIButton sender)
    {
        BlinkID.Instance().Scan();

        //This wont transition
        base.PerformSegue("DemographicSegue", this);
    }

    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
        // Release any cached data, images, etc that aren't in use.
    }

}

class CustomDelegate : BlinkIDDelegate
{
    private ViewController _viewController;

    public CustomDelegate(ViewController viewController)
    {
        _viewController = viewController;

    }

    #region implemented abstract members of BlinkIDDelegate
    public override void DidOutputResults(BlinkID blinkid, NSDictionary[] results)
    {
        var result = results[0];

        var firstName = result.ValueForKey((NSString)"Customer First Name").ToString();
        var middleName = result.ValueForKey((NSString)"Customer Middle Name").ToString();
        var lastName = result.ValueForKey((NSString)"Customer Family Name").ToString();
        var dateOfBirth = result.ValueForKey((NSString)"Date of Birth").ToString();

        string folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        var conn = new SQLiteConnection(System.IO.Path.Combine(folder, "demo.db"));

        conn.DropTable<Demographic>();
        conn.CreateTable<Demographic>();

        var demographic = new Demographic();

        demographic.FirstName = firstName;
        demographic.LastName = lastName;
        demographic.MiddleName = middleName;
        demographic.DateOfBirth = DateTime.ParseExact(dateOfBirth, "Mdyyyy", CultureInfo.InvariantCulture);
        demographic.DemographicId = 1;

        conn.DeleteAll<Demographic>();

        conn.Insert(demographic);

        //this wont transition
        _viewController.PerformSegue("DemographicSegue", _viewController);

        //    _viewController.WelcomeView.Hidden = true;
        //    _viewController.DemographicView.Hidden = false;
        //    _viewController.FirstNameTextField.Text = demographic.FirstName;
    }

    #endregion
}

}

From: Pickles112358 notifications@github.com<mailto:notifications@github.com> Reply-To: BlinkID/blinkid-xamarin reply@reply.github.com<mailto:reply@reply.github.com> Date: Wednesday, June 29, 2016 at 11:34 AM To: BlinkID/blinkid-xamarin blinkid-xamarin@noreply.github.com<mailto:blinkid-xamarin@noreply.github.com> Cc: Matthew Cooper matthewc@atiba.com<mailto:matthewc@atiba.com>, Author author@noreply.github.com<mailto:author@noreply.github.com> Subject: Re: [BlinkID/blinkid-xamarin] Finished Scanning Handler (#2)

Yes, the issue here is that when calling a Scan() method, we present our scanning view controller internally. So, when you try to segue, you are not transitioning from scanning view controller (current topmost view controller) but from view controller that had the button. In the next release we will expose the scanning view controller so you can transition from it.

In the meantime you can access it from the class that called the Scan() method like this: this.PresentedViewController

You could also look at this thread for fetching the topmost view controller: https://forums.xamarin.com/discussion/24689/how-to-acces-the-current-view-uiviewcontroller-from-an-external-service

Kind regards, Dino

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BlinkID/blinkid-xamarin/issues/2#issuecomment-229413341, or mute the threadhttps://github.com/notifications/unsubscribe/ABXggUD_fSiwxqn-XF1Ul9hYGSuZP2dAks5qQp6vgaJpZM4JBTmX.

Matthew Cooper

6153893357x127 matthewc@atiba.com

ATIBA | ENGAGING SOLUTIONS Network Services | Custom Software | Website Development | Mobile Apps Interactive Marketing | Microsoft Certified Partner | Dell GeoPartner www.atiba.comhttp://www.atiba.com

dgust6 commented 8 years ago

As scanning view controller is on top of your current view controller, you cannot perform segue from it. What you can do is fetch the topmost controller like i mentioned in my previous comment and perform segue from there. So instead of calling:

base.PerformSegue("DemographicSegue", this);

Try calling:

base.PresentedViewController.PerformSegue("DemographicSegue", base.PresentedViewController);

or:

UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController.PerformSegue("DemographicSegue", UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController);

If that doesn't work, try presenting your view controller with another method: https://developer.xamarin.com/api/member/MonoTouch.UIKit.UIViewController.PresentViewController/

Kind regards, Dino

matthewjcooper commented 8 years ago

None of these options are working. The only one that came close was manually presenting the viewcontroller, it actually showed it, but then the blink id controller took over again and closed it.

matthewjcooper commented 8 years ago

I'v decided to just use swift and xcode instead of xamarin, so i can use more of the features of your sdk.

Cerovec commented 8 years ago

This would be our advice for all those who don't have problems with native SDK. You have much lower level control in our Native SDK.

However, if you want to use Xamarin for the rest of your app, you can just work with the iOS binding project in this repository, which is located in BindingSource folder. Basically, xamarin component uses the library and API defined by that project.

We can provide you with all the help for native SDK.