Skip to content

piuholo/react-native-nfc-manager

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-nfc-manager

Bring NFC feature to React Native. Inspired by phonegap-nfc and react-native-ble-manager

Supported Platforms

  • Android (API 10+)

Install

npm i --save react-native-nfc-manager

Link Native Library with react-native link

react-native link react-native-nfc-manager

Example

Look into example/App.js as a starting point.

API

This library provide a default export NfcManager and a named export NdefParser, like this:

import NfcManager, {NdefParser} from 'react-native-nfc-manager'

All methods in NfcManager return a Promise object and are resolved to different types of data according to individual API.

NdefParser is an utility class to parse some well-known NDEF format, currently only support RTD URI.

NfcManager API

start()

Init the module.

isEnabled()

Check if the NFC is enabled. Returned Promise resolved to a boolean value to indicate whether NFC is enabled.

goToNfcSetting()

Direct the user to NFC setting.

getLaunchTagEvent()

Get the NFC tag object which launches the app. Returned Promise resolved to the NFC tag object launching the app and resolved to null if the app isn't launched by NFC tag.

registerTagEvent(listener)

Start to listen to ANY NFC tags.

Arguments

  • listener - function - the callback when discovering NFC tags

Examples

NfcManager.registerTagEvent(tag => {
    console.log('Tag Discovered', tag);
})

unregisterTagEvent()

Stop listening to NFC tags.

NdefParser API

parseUri(ndef)

Try to parse uri from a NdefMessage, return an object with an uri property.

Arguments

  • ndef - object - this object should be obtained from nfc tag object with this form: tag.ndefMessage[0]. (NFC tag object can be obtained by getLaunchTagEvent or registerTagEvent)

Examples

let {uri} = NdefParser.parseUri(sampleTag.ndefMessage[0]);
console.log('parseUri: ' + uri);

About

NFC module for React Native

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 72.6%
  • JavaScript 27.4%