parvus
parvus

Reputation: 6016

Xamarin.iOS Write NFC

How can I use Xamarin.iOS to write an NFC tag? Assuming this is not yet possible - since I can't find anything mentioning this in the API documentation or in the release notes of Xamarin Forms: is there a timeline when this can be expected?

Also, is there currently a way around it?

Upvotes: 1

Views: 1970

Answers (1)

Saamer
Saamer

Reputation: 5099

The beauty of Xamarin.iOS is that everything you can do with the native Apple libraries, you can do in C#. So if something is possible using Swift using the native libraries, you will be able to do it using the C# version of that library, using CoreNFC in your case.

So your next step is just figuring out how to write that Swift/Obj-C code in C#. Using the Apple docs, it's clear that you have only certain types of tags you can write to using an iPhone. So let's choose to go with the NFCISO7816Tag.

First you would have to create a class that implements INFCIso7816Tag. So I created NFCIso7816Tag that implements INFCIso7816Tag. I fill out everything appropriately. And after that, inside my code I create an instance of NFCIso7816Tag and also create an actionHandler delegate of type NFCIso7816SendCompletionHandler. So your code would look something like this:

var tag = new NFCMiFareTag();
tag.SendCommand(new NFCIso7816Apdu(...), actionHandler);

Lastly, don't forget to use the newer devices, since you can't write to NFCs on the older devices!

Here's a list of projects that use CoreNFC, it might give you a headstart on how to implement it yourself!


Edit May 2020:

I wrote an article that explains How to get started with NFC on iOS and Android apps using Xamarin Forms and also created this video. There’s an awesome nuget package for Xamarin forms called Plugin.NFC that also allows you to write Tags using iOS too

Upvotes: 3

Related Questions