internal NfcTag(IntPtr handle) { _tagHandle = handle; _nativeTransceiveCallback = TransceiveCompletedCallback; _nativeVoidCallback = VoidCallback; _nativeTagReadCallback = ReadNdefCallback; }
/// <summary> /// Reads the NDEF formatted data from the NFC tag. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/nfc</privilege> /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception> /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception> public Task <NfcNdefMessage> ReadNdefMessageAsync() { var task = new TaskCompletionSource <NfcNdefMessage>(); NfcNdefMessage ndefMsg = null; Interop.Nfc.TagReadCompletedCallback callback = (int result, IntPtr ndefMessage, IntPtr userData) => { if (result == (int)NfcError.None) { ndefMsg = new NfcNdefMessage(ndefMessage); task.SetResult(ndefMsg); return(true); } return(false); }; int ret = Interop.Nfc.Tag.ReadNdef(_tagHandle, callback, IntPtr.Zero); if (ret != (int)NfcError.None) { Log.Error(Globals.LogTag, "Failed to read ndef message, Error - " + (NfcError)ret); NfcErrorFactory.ThrowNfcException(ret); } return(task.Task); }
/// <summary> /// Constructor of NfcTag /// </summary> public NfcTag() { // A method is need to convert delegate to pass unmanaged layer through Interop call // If we do not convert explicitly it, implicitly convert was occurred // and temporal delegate was created. and it could be released by GC _nativeTransceiveCallback = TransceiveCompletedCallback; _nativeVoidCallback = VoidCallback; _nativeTagReadCallback = ReadNdefCallback; }