Added: iOS Implementation from Borepin

This commit is contained in:
TheJoKlLa 2021-03-31 14:34:26 +02:00
parent 9c73cc4923
commit 4420dbf1b1
4 changed files with 163 additions and 0 deletions

66
NFC_iOS/Card_iOS.cs Normal file
View File

@ -0,0 +1,66 @@
//using System;
//using System.Threading;
//using NFC.Interfaces;
//using CoreNFC;
//using Foundation;
//namespace NFC_iOS
//{
// public class Card_iOS : ICard
// {
// private NFCTagReaderSession _session;
// private INFCMiFareTag _tag;
// public Card_iOS(NFCTagReaderSession session, INFCMiFareTag tag)
// {
// _session = session;
// _tag = tag;
// }
// public void Connect()
// {
// var counter = new CountdownEvent(1);
// NSError err = null;
// _session.ConnectTo(_tag, (error) =>
// {
// err = error;
// counter.Signal();
// });
// counter.Wait();
// if (err != null)
// {
// throw new Exception(err.LocalizedDescription);
// }
// }
// public void Disconnect()
// {
// // TODO: decide on which should be used
// //_session.RestartPolling();
// _session.InvalidateSession("card disconnect");
// }
// public APDUResponse Transmit(APDUCommand cmd)
// {
// var counter = new CountdownEvent(1);
// byte[] buf = null;
// _tag.SendMiFareIso7816Command(new NFCIso7816Apdu(NSData.FromArray(cmd.Data)), (response, sw1, sw2, NSError) =>
// {
// // reassembly the original apdu message
// buf = new byte[response.Length + 2];
// response.ToArray().CopyTo(buf, 0);
// buf[response.Length + 0] = sw1;
// buf[response.Length + 1] = sw2;
// counter.Signal();
// });
// counter.Wait();
// return new APDUResponse(buf);
// }
// }
//}

24
NFC_iOS/Hardware_iOS.cs Normal file
View File

@ -0,0 +1,24 @@
//using System;
//using NFC.Interfaces;
//using CoreNFC;
//namespace NFC_iOS
//{
// public class Hardware_iOS : IHardware
// {
// public bool IsAvailable()
// {
// return NFCReaderSession.ReadingAvailable;
// }
// public String[] GetReaders()
// {
// return new String[] { "main" };
// }
// public IReader OpenReader(String readerID)
// {
// return new Reader_iOS();
// }
// }
//}

View File

@ -4,4 +4,12 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NFC\NFC.csproj" />
</ItemGroup>
</Project>

65
NFC_iOS/Reader_iOS.cs Normal file
View File

@ -0,0 +1,65 @@
//using NFC.Interfaces;
//using System;
//using CoreNFC;
//using Foundation;
//namespace NFC_iOS
//{
// public class Reader_iOS : 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");
// }
// }
//}