internal NfcTag(IntPtr handle) { _tagHandle = handle; _nativeTransceiveCallback = TransceiveCompletedCallback; _nativeVoidCallback = VoidCallback; _nativeTagReadCallback = ReadNdefCallback; }
/// <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; }
/// <summary> /// Formats the detected tag that can store the NDEF message. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="keyValue">The key value that may need to format the tag.</param> /// <privilege>http://tizen.org/privilege/nfc</privilege> /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception> /// <exception cref="ArgumentException">Thrown when method fails due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception> public Task <NfcError> FormatNdefMessageAsync(byte[] keyValue) { var task = new TaskCompletionSource <NfcError>(); Interop.Nfc.VoidCallback callback = (int result, IntPtr userData) => { task.SetResult((NfcError)result); return; }; int ret = Interop.Nfc.Tag.FormatNdef(_tagHandle, keyValue, keyValue.Length, callback, IntPtr.Zero); if (ret != (int)NfcError.None) { Log.Error(Globals.LogTag, "Failed to format ndef message, Error - " + (NfcError)ret); NfcErrorFactory.ThrowNfcException(ret); } return(task.Task); }
/// <summary> /// Writes the NDEF formatted data. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="ndefMessage">The NfcNdefMessage object.</param> /// <privilege>http://tizen.org/privilege/nfc</privilege> /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception> /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception> public Task <NfcError> WriteNdefMessageAsync(NfcNdefMessage ndefMessage) { var task = new TaskCompletionSource <NfcError>(); Interop.Nfc.VoidCallback callback = (int result, IntPtr userData) => { task.SetResult((NfcError)result); return; }; int ret = Interop.Nfc.Tag.WriteNdef(_tagHandle, ndefMessage.GetHandle(), callback, IntPtr.Zero); if (ret != (int)NfcError.None) { Log.Error(Globals.LogTag, "Failed to write ndef message, Error - " + (NfcError)ret); NfcErrorFactory.ThrowNfcException(ret); } return(task.Task); }