BlinkID / blinkid-xamarin

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

microblinkFactory is null even when using dependency service #44

Open HassanMehdi17 opened 4 years ago

HassanMehdi17 commented 4 years ago

im testing on IOS.

my constructor:

public MainPage() { InitializeComponent();

        var microblinkFactory = DependencyService.Get<IMicroblinkScannerFactory>();

        string licenseKey = "notreal";
        blinkID = microblinkFactory.CreateMicroblinkScanner(licenseKey);```

the microblinkFactory is getting initialized to null.

this is my appdelegate.cs for my .ios project


using UIKit;

namespace App.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Xamarin.Forms.Forms.Init();

            Xamarin.Forms.DependencyService.Register<Microblink.Forms.iOS.MicroblinkScannerFactoryImplementation>();

            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
    }
}
stephajn commented 3 years ago

Went through this myself. The most important thing with this is that if you try to build or run your app in a simulator, then an underlying dependency is not available. The Microsoftblink.Forms.iOS.MicroblinkScannerFactoryImplementation class calls on a method from the Microblink SDK called SharedInstance. SharedInstance is what is actually returning null. And this will happen even if all you are attempting to do is just BUILD the code toward any target besides a physical device.

mparadina commented 3 years ago

Hi @HassanMehdi17 and @stephajn

The issue here could be connected with git lfs (Git Large File Storage) and downloading larger files when cloning the project.

Make sure that you have git lfs installed since some larger files will not be downloaded if it is not installed. You can also check if larger files have been checked out with the git lfs pull command.

Also to note, make sure that you've entered a valid license key in the project and initialized the license key method before entering the scanning screen.

Regards, Milan

stephajn commented 3 years ago

@mparadina

That's what it was for me. Doing a git lfs pull after getting the initial repository solved the problem beautifully.

On my PC, using Visual Studio, I can successfully compile the Droid project and deploy it onto my physical device. If I want to compile the iOS application and deploy it to my iPhone, I actually have to do all of that from Visual Studio for Mac on my iMac for it to work. Trying to use the Xamarin tooling on my Windows PC in Visual Studio 2019 to build it and deploy it to my physical device seems to result in the native library not being deployed along with the Xamarin based code.

Not sure if there is a project setting or a specific package setting that has to be put in place, but it definitely seems to only work if I build it using Visual Studio for Mac on a macOS machine.