Search code examples
javascriptnfcwindows-phone-8.1proximity

Windows Phone Write NFC Tag


I am trying to write/read some NFC tags using the ProximityDevice class on Windows Phone 8.1. This is the code that writes the tag...

var dataWriter = new Windows.Storage.Streams.DataWriter();
dataWriter.unicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
dataWriter.writeString("test");
var pubId = proximityDevice.publishBinaryMessage
         "Windows:WriteTag.Sample", 
          dataWriter.detachBuffer(),
          proximityWriteTagMessageTransmitCallback);

After writing the tag, which is seemingly successful, I read it. When I do, the data received is only the first character of the string (in this case "t"). I inspected the tag with NFC interactor and it reports the writable size of the tag as 137 bytes and the message size as 17 bytes so space doesn't seem to be the issue.

I have also tested the tags with NFC Launch it and it works fine so I am at a loss for where the issue lies. Any help would be appreciated.

Thanks in advance.


Solution

  • I've solved the issue. Turns out that writing custom text to the tag requires UTF-8 encoding. I changed...

    dataWriter.unicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
    

    to

    dataWriter.unicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.utf8;
    

    Now the data is written to and can be retrieved from the tag properly.