Пример #1
0
        private void ManageCleanOperation()
        {
            //TODO 3. WRITING CARD 5
            Ndef          ndef   = null;
            NfcNdefRecord record = null;

            try
            {
                ndef = Ndef.Get(currentTag);
                if (!CheckWriteOperation(ndef, record))
                {
                    OnNfcTagCleaned?.Invoke(this, false);
                    return;
                }

                ndef.Connect();

                byte[]      empty   = Array.Empty <byte>();
                NdefMessage message = new NdefMessage(new NdefRecord[1] {
                    new NdefRecord(NdefRecord.TnfEmpty, empty, empty, empty)
                });

                ndef.WriteNdefMessage(message);
                OnNfcTagCleaned?.Invoke(this, true);
                return;
            }
            catch (Android.Nfc.TagLostException tlex)
            {
                Debug.WriteLine($"Tag Lost Error: {tlex.Message}");
            }
            catch (Java.IO.IOException ioex)
            {
                Debug.WriteLine($"Tag IO Error: {ioex.Message}");
            }
            catch (Android.Nfc.FormatException fe)
            {
                Debug.WriteLine($"Tag Format Error: {fe.Message}");
            }
            catch
            {
                Debug.WriteLine($"Tag Error");
            }
            finally
            {
                if (ndef?.IsConnected == true)
                {
                    ndef.Close();
                }

                currentTag    = null;
                currentIntent = null;
            }

            OnNfcTagCleaned?.Invoke(this, false);
        }
Пример #2
0
 public override void DidInvalidate(NFCNdefReaderSession session, NSError error)
 {
     //Error
     if (isReadingTag)
     {
         OnNfcTagRead?.Invoke(this, null);
     }
     else if (isWritingTagText)
     {
         OnNfcTagTextWriten?.Invoke(this, false);
     }
     else if (isWritingTagUri)
     {
         OnNfcTagUriWriten?.Invoke(this, false);
     }
     else if (isWritingTagMime)
     {
         OnNfcTagMimeWriten?.Invoke(this, false);
     }
     else if (isCleaningTag)
     {
         OnNfcTagCleaned?.Invoke(this, false);
     }
 }