This is BlinkInput Xamarin implementation based on native iOS and Android BlinkInput SDKs.
Steps for integrating BlinkInput into your Xamarin Forms project:
- In both your
Core
,Droid
andiOS
projects, addBlinkInput.Forms
NuGet package as a reference. - In your
Droid
project, update yourMainActivity.cs
in a following way:- update your
MainActivity
class so that it implementsMicroblink.Forms.Droid.IMicroblinkScannerAndroidHostActivity
. This interface specifies 2 properties and 1 method that you must implement:HostActivity
property must return reference to current host activity.ScanActivityRequestCode
property must return integer that will be used as request code for Android'sStartActivityForResult
invocationScanningStarted
method will be called just before scanning starts. It will receive currently usedMicroblinkScannerImplementation
as a parameter. You should save a reference to this object because you will need it later in your implementation ofOnActivityResult
- override
Activity's
methodOnActivityResult
and pass its parameters to reference ofMicroblinkScannerImplementation
- update your
- Your
iOS
project does not need any modifications. - In your
Core
project, obtain a reference toIMicroblinkScannerFactory
using aDependencyService
- Use a factory to create an instance of
IMicroblinkScanner
. - Use the dependency service to create recognizer you wish to use
- Subscribe to
Messages.ScanningDoneMessage
that will inform you whether the scanning has completed or was cancelled by end user - Using on or more of recognizer objects obtained in step 6., create an instance
IRecognizerCollection
usingIRecognizerCollectionFactory
obtained viaDependencyService
- Create a settings object for desired UI overlay
- Start scanning by invoking method
Scan
on instance ofIMicroblinkScanner
Xamarin Forms sample app is available here.
In your native Android project, add reference to BlinkInput.Android.Binding
NuGet package and follow the integration instructions for BlinkInput Android SDK.
Native Android sample app is available here.
In your native iOS project, add reference to BlinkInput.iOS.Binding
NuGet package and follow the integration instructions for BlinkInput iOS SDK.
Native iOS sample app is available here.
If you do not wish to use BlinkInput NuGet packages, you can directly reference binding projects in your solutions. Just make sure that following conditions are met:
- all large binary files have been checked out
- to ensure that all files have been checked out, please make sure that you have installed Git Large File Storage and that you have fetched all LFS files with
git lfs pull
command.
- to ensure that all files have been checked out, please make sure that you have installed Git Large File Storage and that you have fetched all LFS files with
- your solution has referenced all dependencies of the project that you are referencing
Binding
- Xamarin iOS and Android Binding Libraries and Xamarin Forms project from which all mentioned NuGet packages were builtSamples
- Xamarin.iOS, Xamarin.Android and Xamarin.Forms sample applications
- Download latest AAR from Android SDK repository
- Replace
Binding/Android/Jars/LibBlinkInput.aar
with latest AAR - Open
Binding/Forms/BlinkInput.Forms/BlinkInput.Forms.sln
solution - If needed, update
Transforms/Metadata.xml
inAndroidBinding
project. - Right-click the
AndroidBinding
project, selectOptions
, underNuGet Package
section selectMetadata
- Update
Version
on tabGeneral
- Update
Release notes
on tabDetails
- Rebuild the
AndroidBinding
project
-
Download latest Microblink.bundle and Microblink.framework from iOS SDK repository
-
Replace
Binding/iOS/Microblink.bundle
andBinding/iOS/Microblink.framework
with latest versions -
Generate new
ApiDefinitions.cs
andStructsAndEnums.cs
with latest version of Objective Sharpie, but DO NOT OVERWRITE existingApiDefiniton.cs
andStructs.cs
- you can generate new
ApiDefinitions.cs
andStructsAndEnums.cs
with following command (replaceiphoneos13.3
with latest SDK you have on your Mac):
cd Binding/iOS sharpie bind -sdk iphoneos13.3 Microblink.framework/Headers/Microblink.h -scope Microblink.framework/Headers -namespace Microblink -c -F .
- you can generate new
-
Manually merge new structures from generated
StructsAndEnums.cs
into existingStructs.cs
while fixing compile errorssharpie
generates enums with underlying types such asnuint
ornint
which are not supported by latest version of C# - you must replace those withuint
orint
types.
-
Manually merge new API classes from generated
ApiDefinitions.cs
into existingApiDefinition.cs
- note that diff between those two files may be quite large, as
ApiDefinition.cs
has been manually edited to ensure correct compilation and correct exposure of all native SDK features. Focus only on adding new recognizers and parsers. Usually it shuold not be necessary to add other classes.
- note that diff between those two files may be quite large, as
-
Open
Binding/Forms/BlinkInput.Forms/BlinkInput.Forms.sln
solution -
From
iOSBinding
project removeMicroblink.bundle
and re-add it back- this will ensure that all new resources from new bundle are correctly added to the project
- also make sure that all resources within added
Microblink.bundle
haveBuildAction
set toBundleResource
-
Right-click the
iOSBinding
project, selectOptions
, underNuGet Package
section selectMetadata
-
Update
Version
on tabGeneral
-
Update
Release notes
on tabDetails
-
Rebuild the
iOSBinding
project and fix any compile errors that may have been introduced in steps 4. and 5.
- Ensure that both Android and iOS native binding libraries have been updated as explained above
- Open
Binding/Forms/BlinkInput.Forms/BlinkInput.Forms.sln
solution - Right-click the
BlinkInput.Forms.Core
project, selectOptions
, underNuGet Package
section selectMetadata
- Update
Version
on tabGeneral
- Update
Release notes
on tabDetails
- Do the same for
BlinkInput.Forms.Android
,BlinkInput.Forms.iOS
andBlinkInput.Forms.NuGet
projects - in
BlinkInput.Forms.Core
add interfaces for new functionality (e.g. new recognizer) - add implementation for those interfaces in
BlinkInput.Forms.Android
andBlinkInput.Forms.iOS
projects - rebuild both
BlinkInput.Forms.Core
,BlinkInput.Forms.Android
andBlinkInput.Forms.iOS
projects
- Ensure that all projects have been updated as described above
- this includes Android and iOS native binding libraries and Xamarin Forms core and platform implementations libraries
- Open
Binding/Forms/BlinkInput.Forms/BlinkInput.Forms.sln
solution - Make sure
Release
build type is selected inVisual Studio
- Right-click on
BlinkInput.Forms.NuGet
project and selectCreate NuGet package
- all projects will be built and their respective NuGet packages will be created in their
bin/Release
folder
- all projects will be built and their respective NuGet packages will be created in their
- Upload packages to NuGet
This section describes how to create your scan activity with BlinkInput SDK, natively in Android and wrap it to Xamarin. For that purpose, we have prepared AndroidCustomUI sample.
Steps to wrap custom functionality to Xamarin:
- Implement it natively for Android - create Android library:
- make sure that you are not using any resources from the BlinkInput Android SDK in resource files inside your library, otherwise, you will get compile errors while generating Xamarin bindings from Android library
- we have created BlinkInputWrapper Android Studio project which contains LibBlinkInputWrapper Android library module with custom scan activity
- Build .aar archive from the library module:
- we have built
LibBlinkInputWrapper-release.aar
from our Android library module
- we have built
- Create a new Xamarin Bindings Library for Android:
- add a dependency to
BlinkInput.Android.Binding
nuget package - add
.aar
toJars
folder and set the Build Action for.aar
to LibraryProjectZip - we have prepared CustomUIBinding project inside CustomUISample solution
- add a dependency to
- You can use the Bindings Library in the application project:
- first, add a reference to the created Bindings Library
- add a dependency to
BlinkInput.Android.Binding
- we have prepared sample application project CustomUIApp inside CustomUISample solution