Home › Forums › Ask the Flomies › Flomio SDK with Xamarin
Tagged: Flomio SDK, Xamarin
-
AuthorPosts
-
May 6, 2016 at 11:17 am #55418
I’m using Xamarin iOS and c# for my event scanner app. Is there any support available for that in the Flomio SDK?
Best regards
Ulrich
May 6, 2016 at 12:24 pm #55420Hi Ulrich, we don’t offer Xamarin support at this time. You can pay us to build that out for you at $150/hr but it’s likely better for you to build it out yourself on top of the provided device drivers.
Is your project “for fun” or for an enterprise application?
thanks,
RichardMay 7, 2016 at 5:21 am #55423Although we don’t support Xamarin, we do support Cordova. If you are ok with coding in JavaScript rather than C#, this may work for you.
For purchasing our products, you can order from our web store here. We also sell on Amazon but currently only the ACR1255U-J1. We’ll be selling more OEM products through Amazon soon.
best,
RichardMay 19, 2016 at 7:11 am #55508Hi Ulrich,
have you looked into binding it as described here: https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/ ?
I want to use it with Xamarin too, but I will also be looking into using it with Xamarin.Forms (wrapping and binding both libraries). If there isn’t anything existing, maybe I can release a package for you afterwards if everything works.
Just waiting for my Flomio to find it’s way through customs right now ๐
June 13, 2016 at 3:40 pm #55724I got it working on Xamarin.iOS. Still, there is a bug in Objective Sharpie that hinders building the project. But I changed the generated classes to fix this. So if you are still interested, I can give you the DLL file ๐
I will upload the code to github once the bug in objective sharpie is fixed.
June 26, 2017 at 11:42 am #60218Did this ever get posted to github? I have a crash in my current binding when trying to authenticate the the reader on iOS and canโt for the life of me figure out what is going on in the ACS static library.
June 27, 2017 at 2:40 am #60233Hey, no i haven’t uploaded it since I’m working on something else now based on PN532 instead of ACR-1255-J1. But I can check later today if the bug was fixed or at least create it manually again and upload it so that you can use it ๐
June 27, 2017 at 6:33 am #60235https://github.com/Falco20019/FloBLEPlus.iOS
This should do the job ๐ Take care to include the obj folder, since there are the objective sharpie generated classes in it which I edited manually. If you have problems, I could also supply a pre-build binary (would have to start my Mac for that).
For authentication is use:
_bluetoothReader.AuthenticateWithMasterKey(@"41 43 52 31 32 35 35 55 2D 4A 31 20 41 75 74 68".ToByteArray());
inside my[Export("bluetoothReader:didAttachPeripheral:error:")] public virtual void DidAttachPeripheral(ABTBluetoothReader bluetoothReader, CBPeripheral peripheral, NSError error)
Method.
June 27, 2017 at 3:28 pm #60245Hey Benjamin! Thank you so much for the quick response! I really hope this isn’t asking for too much, but if you don’t mind including your example project to your linked git repo, that would be amazing. I’m an American living in Stockholm and will happily send you some Kex or Marabou Chocolate for your troubles. I think you and I are the only people in the world working on something like this
I am seeing the same crash with the binding you linked which tells me something is probably wrong in my example.
In a my binding I was implementing an Interface to work as a standard delegate pattern from iOS.
My bluetooth helper looks like this after trying to implement the binding:
public class BluetoothHelper : NSObject, ICBCentralManagerDelegate { private List<CBPeripheral> peripherals; private ABTBluetoothReaderManager manager; public ABTBluetoothReader Reader; private CBCentralManager centralManager; public ReaderDelegate ReaderDelegate; public ReaderManagerDelegate ManagerDelegate; public IBluetoothHelperDelegate BluetoothHelperDelegate; public BluetoothHelper() { this.manager = new ABTBluetoothReaderManager(); this.ManagerDelegate = new ReaderManagerDelegate(this); this.manager.Delegate = this.ManagerDelegate; this.centralManager = new CBCentralManager(this, null); this.centralManager.Delegate = this; this.peripherals = new List<CBPeripheral>(); } public List<CBPeripheral> Peripherals { get { return peripherals; } } public void UpdatedState(CBCentralManager central) { if (central.State == CBCentralManagerState.PoweredOn) { centralManager.ScanForPeripherals(peripheralUuids: null); } else { centralManager.StopScan(); } } [Export("centralManager:didDiscoverPeripheral:advertisementData:RSSI:")] public void DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) { if (!peripherals.Contains(peripheral) && !string.IsNullOrWhiteSpace(peripheral.Name)) { peripherals.Add(peripheral); BluetoothHelperDelegate?.UpdatedPeripherals(); } } [Export("centralManager:didConnectPeripheral:")] public void ConnectedPeripheral(CBCentralManager central, CBPeripheral peripheral) { manager.DetectReaderWithPeripheral(peripheral); } [Export("centralManager:didDisconnectPeripheral:error:")] public void DisconnectedPeripheral(CBCentralManager central, CBPeripheral peripheral, NSError error) { throw new System.NotImplementedException(); } [Export("centralManager:didFailToConnectPeripheral:error:")] public void FailedToConnectPeripheral(CBCentralManager central, CBPeripheral peripheral, NSError error) { var a = ""; } public void ConnectToScannerAtIndex(int index) { centralManager.ConnectPeripheral(peripherals[index]); } public void StopScan() { centralManager.StopScan(); } } public class ReaderManagerDelegate: ABTBluetoothReaderManagerDelegate { private BluetoothHelper _helper; public ReaderManagerDelegate(BluetoothHelper helper) { _helper = helper; } public override void DidDetectReader(ABTBluetoothReaderManager bluetoothReaderManager, ABTBluetoothReader reader, CBPeripheral peripheral, NSError error) { if (error == null) { _helper.Reader = reader; _helper.ReaderDelegate = new ReaderDelegate(_helper); _helper.Reader.Delegate = _helper.ReaderDelegate; _helper.Reader.AttachPeripheral(peripheral); } } } public class ReaderDelegate: ABTBluetoothReaderDelegate { private BluetoothHelper _helper; public ReaderDelegate(BluetoothHelper helper) { _helper = helper; } public override void DidAttachPeripheral(ABTBluetoothReader bluetoothReader, CBPeripheral peripheral, NSError error) { if (error == null) { _helper.Reader.AuthenticateWithMasterKey(@"41 43 52 31 32 35 35 55 2D 4A 31 20 41 75 74 68".ToByteArray()); } } public override void DidChangeCardStatus(ABTBluetoothReader bluetoothReader, ABTBluetoothReaderCardStatus cardStatus, NSError error) { base.DidChangeCardStatus(bluetoothReader, cardStatus, error); } public override void DidReturnEscapeResponse(ABTBluetoothReader bluetoothReader, NSData response, NSError error) { base.DidReturnEscapeResponse(bluetoothReader, response, error); } public override void DidReturnResponseApdu(ABTBluetoothReader bluetoothReader, NSData apdu, NSError error) { base.DidReturnResponseApdu(bluetoothReader, apdu, error); } public override void DidReturnAtr(ABTBluetoothReader bluetoothReader, NSData atr, NSError error) { base.DidReturnAtr(bluetoothReader, atr, error); } public override void DidAuthenticateWithError(ABTBluetoothReader bluetoothReader, NSError error) { base.DidAuthenticateWithError(bluetoothReader, error); } } public interface IBluetoothHelperDelegate { void UpdatedPeripherals(); Task AuthenticatedReader(); }
Again, I hate to ask for ideas, but am at the end of my rope on this. It feels like everything should really be working.
June 27, 2017 at 3:56 pm #60248Hi Tim,
I will give your code a review tomorrow and check where it differs from mine. I faintly remember that I also had some problems initially that took me some time. A lot of time went into getting those delegates and export attributes right.
I also had a feeling that not too many people are working on that low of a level with the reader. I assume most are just using the normal SDK with NDEF. That’s why I waited with uploading my stuff to GitHub.
I’m in Germany, so we should even share the same timezone. I am pretty confident that we can get it to work tomorrow ๐ so don’t give up and just get a rest.
June 28, 2017 at 3:56 am #60255Hi Tim, here is the reviewed code. I included my changes with a TODO comment. The only remaining difference is, that I am using mostly WeakDelegates over Delegates. But since both should work equally, I left them in your code. I also have most of my delegate methods as virtual. Can’t tell you why I did it and if it was needed.
I use ScanForPeripherals variant with options since I think the one without had a problem.
In DiscoveredPeripheral, I also check the peripheral name. I sometimes got a peripheral that is not the FloBLE device. Doing authentication on that would also result in an exception.
I hope this should fix your problem. If it doesn’t, I can offer you to extract my whole NFC class. I also added some methods to better work with TransmitApdu and DidReturnResponseApdu in a natural way using Tasks. (You call the method TransceiveApduCommand with your APDU and receive a Task<APDUResponse> that you can await and in case of error being not null having an exception thrown.)
using System; using System.Collections.Generic; using System.Threading.Tasks; using CoreBluetooth; using Flomio.iOS; using Foundation; namespace NFC.iOS { public class BluetoothHelper : NSObject, ICBCentralManagerDelegate { private List<CBPeripheral> peripherals; private ABTBluetoothReaderManager manager; public ABTBluetoothReader Reader; private CBCentralManager centralManager; public ReaderDelegate ReaderDelegate; public ReaderManagerDelegate ManagerDelegate; public IBluetoothHelperDelegate BluetoothHelperDelegate; public BluetoothHelper() { this.manager = new ABTBluetoothReaderManager(); this.ManagerDelegate = new ReaderManagerDelegate(this); this.manager.Delegate = this.ManagerDelegate; this.centralManager = new CBCentralManager(this, null); this.centralManager.Delegate = this; this.peripherals = new List<CBPeripheral>(); } public List<CBPeripheral> Peripherals { get { return peripherals; } } public virtual void UpdatedState(CBCentralManager central) // TODO: Changed { if (central.State == CBCentralManagerState.PoweredOn) { centralManager.ScanForPeripherals(peripheralUuids: null, options: (NSDictionary)null); // TODO: Changed! } else { // TODO: You may also need to cancel peripherals centralManager.StopScan(); } } [Export("centralManager:didDiscoverPeripheral:advertisementData:RSSI:")] public void DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) { if (!peripherals.Contains(peripheral) && !string.IsNullOrWhiteSpace(peripheral.Name) && peripheral.Name.StartsWith("ACR", StringComparison.Ordinal)) // TODO: Needed ACR check { peripherals.Add(peripheral); BluetoothHelperDelegate?.UpdatedPeripherals(); } } [Export("centralManager:didConnectPeripheral:")] public virtual void ConnectedPeripheral(CBCentralManager central, CBPeripheral peripheral) // TODO: Changed! { manager.DetectReaderWithPeripheral(peripheral); } [Export("centralManager:didDisconnectPeripheral:error:")] public virtual void DisconnectedPeripheral(CBCentralManager central, CBPeripheral peripheral, NSError error) // TODO: Changed! { throw new NotImplementedException(); } [Export("centralManager:didFailToConnectPeripheral:error:")] public virtual void FailedToConnectPeripheral(CBCentralManager central, CBPeripheral peripheral, NSError error) // TODO: Changed! { // Remove and rediscover: peripherals.Remove(peripheral); } public void ConnectToScannerAtIndex(int index) { // TODO: Maybe use centralManager.CancelPeripheralConnection on old connection before centralManager.ConnectPeripheral(peripherals[index]); } public void StopScan() { centralManager.StopScan(); } } public class ReaderManagerDelegate : ABTBluetoothReaderManagerDelegate { private BluetoothHelper _helper; public ReaderManagerDelegate(BluetoothHelper helper) { _helper = helper; } public override void DidDetectReader(ABTBluetoothReaderManager bluetoothReaderManager, ABTBluetoothReader reader, CBPeripheral peripheral, NSError error) { if (error == null) { // TODO: Detach reader if had one attached: _helper.Reader?.Detach(); _helper.Reader = reader; _helper.ReaderDelegate = new ReaderDelegate(_helper); _helper.Reader.Delegate = _helper.ReaderDelegate; _helper.Reader.AttachPeripheral(peripheral); } else { // Disconnect, not a reader: //_helper.centralManager.CancelPeripheralConnection(peripheral); // TODO: Maybe needed? } } } public class ReaderDelegate : ABTBluetoothReaderDelegate { private BluetoothHelper _helper; public ReaderDelegate(BluetoothHelper helper) { _helper = helper; } public override void DidAttachPeripheral(ABTBluetoothReader bluetoothReader, CBPeripheral peripheral, NSError error) { if (error == null) { _helper.Reader.AuthenticateWithMasterKey(@"41 43 52 31 32 35 35 55 2D 4A 31 20 41 75 74 68".ToByteArray()); } } public override void DidChangeCardStatus(ABTBluetoothReader bluetoothReader, ABTBluetoothReaderCardStatus cardStatus, NSError error) { // TODO: Added implementation if (error == null) { // Power on card to get ATR: switch (cardStatus) { case ABTBluetoothReaderCardStatus.Present: bluetoothReader.PowerOnCard(); break; case ABTBluetoothReaderCardStatus.Absent: // Tag lost break; } } } public override void DidReturnEscapeResponse(ABTBluetoothReader bluetoothReader, NSData response, NSError error) { base.DidReturnEscapeResponse(bluetoothReader, response, error); } public override void DidReturnResponseApdu(ABTBluetoothReader bluetoothReader, NSData apdu, NSError error) { base.DidReturnResponseApdu(bluetoothReader, apdu, error); } public override void DidReturnAtr(ABTBluetoothReader bluetoothReader, NSData atr, NSError error) { base.DidReturnAtr(bluetoothReader, atr, error); } public override void DidAuthenticateWithError(ABTBluetoothReader bluetoothReader, NSError error) { base.DidAuthenticateWithError(bluetoothReader, error); } } public interface IBluetoothHelperDelegate { void UpdatedPeripherals(); Task AuthenticatedReader(); } }
June 28, 2017 at 9:05 am #60256You are amazing! Thank you sooooooo much Benjamin, I’ll take a look right now!
June 28, 2017 at 2:37 pm #60258Ok, Benjamin, I know we are really close to getting this working. I added a repository with a sample app on the binding. I really know I am asking a lot and really appreciate your eyes on this.
https://github.com/trsneed/FloBLEPlus.iOS
I am still getting the same crash (this time things look better though). On Anuthenticate with Master Key, I get a crash that says:
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[ABTAcr1255uj1Reader checksumFromBuffer:length:]: unrecognized selector sent to instance
One thing I did notice is the binding linked didn’t include the .a file from ACS, so I used the one provided. I really really appreciate your time and help on this. It feels like we are super close on narrowing this down.
June 28, 2017 at 2:59 pm #60259It seems like he is missing the checksumFromBuffer method in the Reader class. You should check the generated files in obj and the header files from the original library.
I will give it a try tomorrow in my Mac. Then I should be able to tell you exactly where it is getting stuck.
I think the .a file should be embedded in the dll generated. I can send you my dll file which is working. Then you should be also able to just use it as reference in your project without any dependencies.
June 29, 2017 at 2:45 am #60262My thoughts exactly, I don’t see a public method for checksumFromBuffer in the reader class. Thank you again!
June 29, 2017 at 3:43 am #60263Can you just try to build against that dll? Just to make sure it’s not a problem with the wrapper library: https://www.dropbox.com/s/vz644kzepi9vi1l/Flomio.iOS.dll?dl=0
According to this thread, the error message occures in case you didn’t use the “-ObjC” linker flag: https://flomio.com/forums/topic/floble-cannot-pair-and-flojack-cannot-read-tags/
You libSDKClasses.linkwith.cs should look like this:
[assembly: LinkWith (“libSDKClasses.a”, LinkTarget.ArmV7 | LinkTarget.Simulator, SmartLink = true, ForceLoad = false, IsCxx=true, Frameworks = “MediaPlayer”, LinkerFlags = “-lc++ -ObjC”)]If you are having all in one iOS project, you also need to follow those instructions for your project:
In Targets -> YourAppTarget -> Build Settings -> Linking -> Other Linker Flags add โ-lc++โ and โ-ObjCโ
In Targets -> YourAppTarget -> Build Options -> Enable Bitcode set to โNoโ
(optional) In Target-> Build Settings-> Apple LLVM 7.0-Preprocessing -> Preprocessor Macros add โDEBUGLOGโ
In Targets -> YourAppTarget -> General -> Link Binary with Libraries, add MediaPlayer.FrameworkJune 30, 2017 at 3:39 pm #60269SUCCESS!!!! Benjamin, thank you so much. I owe you huge! If you don’t mind shooting me an email (trsneed@gmail.com) I’d like to swap some information ๐
- This reply was modified 7 years, 5 months ago by Tim.
June 30, 2017 at 6:34 pm #60271@Benjamin and @Tim, I’ve been following this thread closely and think you both are doing awesome work. Please let us know if there’s anything we can do to help. As a further vote of encouragement, I’ve set up a coupon for a free tshirt to be shipped to you (also free). To redeem, just add one of these tshirt options to your shopping cart, choose your size, and enter coupon code “freetshirt”. This will cover your shirt order and shipping, you’ll just need to enter your ship to address to complete checkout.
Thanks again for your efforts to make NFC more accessible.
RichardOctober 5, 2017 at 4:29 am #61224Hello guys!
I’m having a lot of issues trying to parse the objective C library on Xamarin.
I tried everything described on this post, but no success at all.
I even downloaded the source code you guys posted on GitHub, but so far always the same error (Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[ABTBluetoothReader authenticateWithMasterKey:length:]: unrecognized selector sent to instance 0x1c0a22f20).Were you guys able to make it work properly?
If so, could you guys help me on this subject?Thanks in advance ๐
October 5, 2017 at 5:20 am #61226Sounds like you miss the linker Flags. Make sure you followed especially the last lines of my post here: https://flomio.com/forums/topic/flomio-sdk-2/#post-60263
January 22, 2018 at 5:14 pm #62038hello Benjamin or anyone that has a working ios wrapper/testapp for xamarin
is there any way you can repost your xamarin wrapper for ios. the link in the post is dead and we are scrambling to make the floble plus work for an upcoming trade show app this weekany help would be greatly appreciated
January 22, 2018 at 5:23 pm #62039Give me some notes what your problem is and I can try to give you some tips. Donโt have the wrapper at hand right now. Could try to rebuild it on Wednesday if itโs any help for you.
I released my code here: https://github.com/Falco20019/FloBLEPlus.iOS
Maybe this helps you already
January 22, 2018 at 5:51 pm #62040to the note above we are more than willing to pay for the wrapper if you can get us something that works. we just dont have time to mess around for this event
January 22, 2018 at 10:33 pm #62042when we try to use the code you posted earlier in june but we kept getting errors. so s we read down the post we see you wanted tim to use a wrapper you made and that seem to bring him success. we are fighting time table while trying to wrap up other projects so we would be more than happy paying you on wednesday or any time this week that is convenient for you to create the wrapper for our project and getting it up and running as we have about 40 devices that need these scanners for a trade show that has to read ITN bcard badges. we work day and night so time is not an issue to work with us
let me know what works and what we can pay you to take care of this for us
thanks in advance
January 23, 2018 at 2:14 am #62044I just took the time and reuploaded it since you are in a hurry. Check if it works for you:
https://www.dropbox.com/s/xle0dmf5me1fq9g/Flomio.iOS.dll?dl=0If it works, just make a donation at https://paypal.me/falco20019 ๐ If you prefer invoice just get in contact with me.
August 27, 2018 at 1:43 pm #63899Hi Guys,
Here are Xamarin bindings for the Flomio iOS SDK for those that want to avail of the features on top of reader drivers that our iOS SDK provides.
Scott
-
AuthorPosts
You must be logged in to reply to this topic.