temporarily removed iOS NFC implementation (commented out)

This commit is contained in:
Jannis Rieger 2021-02-05 15:08:58 +01:00
parent d865103558
commit 5f44194f0f
4 changed files with 138 additions and 135 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>8.0.30703</ProductVersion> <ProductVersion>8.0.30703</ProductVersion>
@ -26,7 +27,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<MtouchArch>x86_64</MtouchArch> <MtouchArch>x86_64</MtouchArch>
<MtouchLink>Full</MtouchLink> <MtouchLink>SdkOnly</MtouchLink>
<MtouchDebug>true</MtouchDebug> <MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey> <CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup> </PropertyGroup>
@ -78,8 +79,8 @@
<None Include="Info.plist" /> <None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CNFC\Card.cs" /> <Compile Include="CNFC\Card.cs" />
<Compile Include="CNFC\Reader.cs" />
<Compile Include="CNFC\Hardware.cs" /> <Compile Include="CNFC\Hardware.cs" />
<Compile Include="CNFC\Reader.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" /> <InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />
@ -177,8 +178,10 @@
<PackageReference Include="Prism.DryIoc.Forms"> <PackageReference Include="Prism.DryIoc.Forms">
<Version>8.0.0.1909</Version> <Version>8.0.0.1909</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="Xamarin.Forms">
<Version>4.7.0.1351</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

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

View File

@ -1,24 +1,24 @@
using System; //using System;
using CoreNFC; //using CoreNFC;
using NFC; //using NFC;
namespace Borepin.iOS.CNFC //namespace Borepin.iOS.CNFC
{ //{
public class Hardware : IHardware // public class Hardware : IHardware
{ // {
public bool IsAvailable() // public bool IsAvailable()
{ // {
return NFCReaderSession.ReadingAvailable; // return NFCReaderSession.ReadingAvailable;
} // }
public String[] GetReaders() // public String[] GetReaders()
{ // {
return new String[] { "main" }; // return new String[] { "main" };
} // }
public IReader OpenReader(String readerID) // public IReader OpenReader(String readerID)
{ // {
return new Reader(); // return new Reader();
} // }
} // }
} //}

View File

@ -1,66 +1,66 @@
using System; //using System;
using CoreFoundation; //using CoreFoundation;
using CoreNFC; //using CoreNFC;
using Foundation; //using Foundation;
using NFC; //using NFC;
namespace Borepin.iOS.CNFC //namespace Borepin.iOS.CNFC
{ //{
public class Reader : NFCTagReaderSessionDelegate, IReader // public class Reader : NFCTagReaderSessionDelegate, IReader
{ // {
public event ReaderEventHandler CardDiscovered; // public event ReaderEventHandler CardDiscovered;
public event ReaderEventHandler CardLost; // public event ReaderEventHandler CardLost;
private NFCReaderSession _session = null; // private NFCReaderSession _session = null;
private DispatchQueue _queue; // private DispatchQueue _queue;
public void Start() // public void Start()
{ // {
_queue = new DispatchQueue("NFC Reader Queue", true); // _queue = new DispatchQueue("NFC Reader Queue", true);
// sessions cannot be reused // // sessions cannot be reused
_session = new NFCTagReaderSession(NFCPollingOption.Iso14443, this, _queue) // _session = new NFCTagReaderSession(NFCPollingOption.Iso14443, this, _queue)
{ // {
AlertMessage = "TODO", // AlertMessage = "TODO",
}; // };
if (_session == null) // if (_session == null)
{ // {
Console.WriteLine("Oh no! The session is null!"); // Console.WriteLine("Oh no! The session is null!");
} // }
_session.BeginSession(); // _session.BeginSession();
} // }
public void Stop() // public void Stop()
{ // {
_session?.InvalidateSession(); // _session?.InvalidateSession();
_session = null; // _session = null;
} // }
public override void DidDetectTags(NFCTagReaderSession session, INFCTag[] tags) // public override void DidDetectTags(NFCTagReaderSession session, INFCTag[] tags)
{ // {
Console.WriteLine("Did detect tags"); // Console.WriteLine("Did detect tags");
Console.WriteLine(tags[0].Type); // Console.WriteLine(tags[0].Type);
//INFCIso7816Tag tag = tags[0].GetNFCIso7816Tag(); // //INFCIso7816Tag tag = tags[0].GetNFCIso7816Tag();
INFCMiFareTag tag = tags[0].GetNFCMiFareTag(); // INFCMiFareTag tag = tags[0].GetNFCMiFareTag();
if (tag != null) // if (tag != null)
{ // {
Console.WriteLine("Card ist valid"); // Console.WriteLine("Card ist valid");
CardDiscovered?.Invoke(this, new Card(session, tag)); // CardDiscovered?.Invoke(this, new Card(session, tag));
} // }
else // else
{ // {
Console.WriteLine("Card is not ISO7816"); // Console.WriteLine("Card is not ISO7816");
} // }
} // }
public override void DidInvalidate(NFCTagReaderSession session, NSError error) // public override void DidInvalidate(NFCTagReaderSession session, NSError error)
{ // {
// TODO: decide what to do // // TODO: decide what to do
Console.WriteLine("reader session invalidated"); // Console.WriteLine("reader session invalidated");
} // }
} // }
} //}