Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

microblinkFactory is null even when using dependency service #44

Open
HassanMehdi17 opened this issue Mar 14, 2020 · 3 comments
Open

microblinkFactory is null even when using dependency service #44

HassanMehdi17 opened this issue Mar 14, 2020 · 3 comments

Comments

@HassanMehdi17
Copy link

HassanMehdi17 commented Mar 14, 2020

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
Copy link

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
Copy link

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
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants