Breyta

Deila með


ReadNFC function

Applies to: Canvas apps

Reads a Near Field Communication (NFC) tag.

Description

Use the ReadNFC function to read an NFC tag that is close to your device. When invoked, the screen displays instructions for scanning an NFC tag, and only returns after the tag has been scanned or it times out.

Column Type Description
Identifier Text The NFC tags identifier if available.
NDEFRecords Table The supported NDEF records found on the tag.

A single NDEFRecord contains the following columns:

Column Type Description
RTD Text The tag's Record Type Definition (RTD). Only Text and URI are supported at this time.
TNF Number The tag's Type Name Format (TNF). Only TNFs of Well Known(1) are supported at this time.
Text Text The text payload of the NFC tag if RTD is TEXTblank otherwise.
URI Hyperlink The URI payload of the NFC tag if RTD is URIblank otherwise.

If the NDEF record isn't supported (for example, the TNF isn't of type Well Known), then it won't be returned as part of the NDEFRecords table.

Always check the payload values for blank using the IsBlank function before using it. You don't need to check the RTD and TNF values yourself as they must be the correct values for Text and URI to have a non-blank value.

Additional RTD and TNF values may be supported in the future. If more values are supported, additional payload columns will also be added. The raw RTD and TNF values are provided for informational purposes and don't need to be consulted if the payload column is checked for blank. More information about these values and their use is available through the NFC Forum.

ReadNFC doesn't require a tag containing NDEF records to be used, but you may still get the tag identifier if one is available.

ReadNFC can only be used in behavior formulas.

Note

  • ReadNFC is only supported when running the app on a native mobile app, such as the iOS and Android apps. Even with a supported player, a device may not support NFC. If your application has Formula-level error management turned on, the function will return an error. Otherwise, an error message will be shown to the user and the function will return a blank record.
  • Ensure your device has the NFC setting enabled to use this capability.

Syntax

ReadNFC()

Examples

Formula Description Result
ReadNFC().Identifier Returns the identifier of the NFC tag if one exists. 04A1C301314003
ReadNFC().NDEFRecords Returns a table of NDEF records found on the NFC tag if they're a supported type and payload. NDEFRecords result with an example record.

Step-by-step example

  1. Create a blank canvas app with Phone format.

  2. Add a Button control.

  3. Double-click the button control to change the button text to Read NFC Tag (or modify the Text property).

  4. Set the OnSelect property of the button control to this formula that will add an item to our collection:

    With(ReadNFC(),
        Set(id, Coalesce(Identifier, "No ID"));
        ForAll(NDEFRecords, Collect(tagRecords, {ID: id, Value: Coalesce(Text, URI)})))
    

    Above formula entered as the OnSelect property of the button.

    This formula reads an NFC tag using the ReadNFC() function, and displays type information about the result. Then it collects the read NFC tags to populate the tagRecords collection to be used for the gallery in the next steps.

  5. Add a Gallery control with a vertical layout.

  6. When prompted, select the tagRecords collection as the data source for this gallery. This action will set the Items property of the Gallery control.

    Data source for gallery selected as tagRecords.

  7. Reposition the gallery control so that it doesn't overlap the button, and change the layout type to Title and subtitle.

    Layout of the gallery.

  8. Change the Title formula in the gallery control to ThisItem.Value and change the Subtitle formula in the gallery control to ThisItem.ID.

    You can also delete the NextArrow from the gallery control since it's not used.

  9. Save and publish the app.

  10. Since the function ReadNFC() can't be used in Power Apps Studio or in a web browser, open your app on a mobile device.

    Tip

    The app might take a few moments to appear on your mobile device. If you don't see the app listed, try refreshing your app list.

  11. Select Read NFC Tag and scan a tag. Repeat the process to add multiple tags to your collection.

    App on mobile device with the NFC Tag reading example and the result inside the gallery.