NFC tag reading
Once the premium module has been added to your app, you may use the following APIs to access its functionality .

Overview

This module allows the reading of NFC tags on iOS. We provide a javascript native bridge to initiate tag reading while the app is open. On supported devices running iOS 12 or later, we also support background tag reading for apps with universal links.

Implementation Guide

Check for NFC availability

Create a function that will receive the availability information. Then open the url gonative://nfc/status?callback=CALLBACK.
For example:
1
// define callback function, do not call it yourself!
2
function nfcStatusCallback(data) {
3
if (data.available) {
4
// show user NFC-related things, e.g. a button to start scanning
5
}
6
}
7
8
// initiate scan
9
window.location.href = 'gonative://nfc/status?callback=nfcStatusCallback';
Copied!

Initiate tag reading

Create a function that will receive the tag data. Then open the url gonative://nfc/readTag with query params:
    callback: a function to receive the data
    message: a string that will be shown in the iOS prompt when scanning for tags
    openUrl: if set to “true” and the the NFC tag has an http or https url, automatically open the url. Data will not be sent to the callback function.
The callback function will be called with an object with the following fields:
    error: if it exists, scanning encountered an error. May be “SystemIsBusy”, “SessionTimeout”, “SessionTerminatedUnexpectedly”, or “Error”.
    prefix: the NDEF tag prefix, e.g. “https://”
    content: the rest of the tag payload after the prefix
    uri: the concatenation of the prefix and the content
For example:
1
var message = 'Hold your device near the NFC tag';
2
3
window.location.href = 'gonative://nfc/readTag?callbackFunction=readTagCallback&message=' + encodeURIComponent(message);
4
5
function readTagCallback(data) {
6
if (data && data.error) {
7
console.log('There was an error scanning for NFC tags');
8
return;
9
}
10
if (data && data.uri) {
11
// do something with data.uri
12
}
13
}
Copied!
To simply open any http(s) url the tag contains:
1
var message = 'Hold your device near the NFC tag';
2
window.location.href = 'gonative://nfc/readTag?openUrl=true&message=' + encodeURIComponent(message);
Copied!
Last modified 1yr ago