WebAPI/WebNFC: Difference between revisions

Line 222: Line 222:
= NFC example =
= NFC example =


== NDEF Utilitiy function ==
== NDEF Utilitiy function for parsing / constructing NDEF records==


Note: This section will go away when {{bug|963556}} lands.
MozNDEFRecord follows the NFC Forum format, and NfcUtils in {{bug|963556}} will provide some basic constants and utility functions to create and parse NDEF records.
MozNDEFRecord has Uint8Array fields containing binary data. In the following examples, we'll just refer to this helper function to convert javascript strings to Uint8Array buffers.
  var NfcUtils = {
    fromUTF8: function nu_fromUTF8(str) {
      var buf = new Uint8Array(str.length);
      for (var i = 0; i < str.length; i++) {
        buf[i] = str.charCodeAt(i);
      }
      return buf;
    }
  }


== NDEF Connect Example ==
== NDEF Connect Example ==
Confirmed users
118

edits