mirror of
https://gitlab.com/fabinfra/fabaccess/nfc.git
synced 2025-03-12 14:51:51 +01:00
Added: iOS Implementation from Borepin
This commit is contained in:
parent
9c73cc4923
commit
4420dbf1b1
66
NFC_iOS/Card_iOS.cs
Normal file
66
NFC_iOS/Card_iOS.cs
Normal 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
24
NFC_iOS/Hardware_iOS.cs
Normal 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();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
@ -4,4 +4,12 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NFC\NFC.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
65
NFC_iOS/Reader_iOS.cs
Normal file
65
NFC_iOS/Reader_iOS.cs
Normal 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");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
Loading…
x
Reference in New Issue
Block a user