mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System;
|
|
using CoreFoundation;
|
|
using CoreNFC;
|
|
using Foundation;
|
|
using NFC;
|
|
|
|
namespace Borepin.iOS.CNFC
|
|
{
|
|
public class Reader : NFCTagReaderSessionDelegate, IReader
|
|
{
|
|
public event ReaderEventHandler CardDiscovered;
|
|
public event ReaderEventHandler CardLost;
|
|
|
|
private NFCReaderSession _session = null;
|
|
private DispatchQueue _queue;
|
|
|
|
public void Start()
|
|
{
|
|
_queue = new DispatchQueue("NFC Reader Queue", true);
|
|
|
|
// sessions cannot be reused
|
|
_session = new NFCTagReaderSession(NFCPollingOption.Iso14443, this, _queue)
|
|
{
|
|
AlertMessage = "TODO",
|
|
};
|
|
|
|
if (_session == null)
|
|
{
|
|
Console.WriteLine("Oh no! The session is null!");
|
|
}
|
|
|
|
_session.BeginSession();
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
_session?.InvalidateSession();
|
|
_session = null;
|
|
}
|
|
|
|
public override void DidDetectTags(NFCTagReaderSession session, INFCTag[] tags)
|
|
{
|
|
Console.WriteLine("Did detect tags");
|
|
|
|
Console.WriteLine(tags[0].Type);
|
|
|
|
//INFCIso7816Tag tag = tags[0].GetNFCIso7816Tag();
|
|
INFCMiFareTag tag = tags[0].GetNFCMiFareTag();
|
|
if (tag != null)
|
|
{
|
|
Console.WriteLine("Card ist valid");
|
|
CardDiscovered?.Invoke(this, new Card(session, tag));
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Card is not ISO7816");
|
|
}
|
|
}
|
|
|
|
public override void DidInvalidate(NFCTagReaderSession session, NSError error)
|
|
{
|
|
// TODO: decide what to do
|
|
Console.WriteLine("reader session invalidated");
|
|
}
|
|
|
|
}
|
|
}
|