# nfc-react-native

> NFC Wrapper

Latest version **0.4.4** (published 2017-02-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install nfc-react-native
pnpm add nfc-react-native
yarn add nfc-react-native
bun add nfc-react-native
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.4 |
| Published | 2017-02-02 |
| First published | 2016-11-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Sebastian Luberriaga |
| Maintainers | lube |

## Links

- npm: https://www.npmjs.com/package/nfc-react-native
- Repository: https://github.com/Lube/nfc-react-native
- Homepage: https://github.com/Lube/nfc-react-native#readme
- Issues: https://github.com/Lube/nfc-react-native/issues
- npm.io page: https://npm.io/package/nfc-react-native

## Recent versions

- 0.4.4 (latest) — 2017-02-02
- 0.4.3 — 2017-02-02
- 0.4.2 — 2017-02-02
- 0.4.1 — 2017-02-01
- 0.4.0 — 2017-02-01
- 0.3.9 — 2017-01-16
- 0.3.8 — 2017-01-16
- 0.3.7 — 2016-12-12
- 0.3.6 — 2016-12-12
- 0.3.5 — 2016-12-12
- 0.3.4 — 2016-12-12
- 0.3.3 — 2016-12-12
- 0.3.2 — 2016-12-12
- 0.3.1 — 2016-12-10
- 0.3.0 — 2016-12-07
- … 7 more at https://npm.io/package/nfc-react-native/versions

## README

# NfcReactNative

nfc-react-native is a react-native module for android to write/read Mifare Classic (NFC) tags.

## Getting started

`$ npm install nfc-react-native --save`

### Mostly automatic installation

`$ react-native link nfc-react-native`

### Manual installation

#### Android

1. Open up `android/app/src/main/java/[...]/MainApplication.java`
  - Add `import es.tiarg.nfcreactnative.NfcReactNativePackage;` to the imports at the top of the file
  - Add `new NfcReactNativePackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
    ```
    include ':nfc-react-native'
    project(':nfc-react-native').projectDir = new File(rootProject.projectDir,  '../node_modules/nfc-react-native/android')
    ```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
    ```
      compile project(':nfc-react-native')
    ```

## Usage
```javascript
import {readTag, writeTag} from 'nfc-react-native'

...
  //get card id
  getCardId()
    .then((card) => {
      console.log(card)
    }).catch((err) => {
      console.log(err)
  })    

  //read multiple sectors + blocks and get card id
  readTag([{ sector: 5, bloques: [1,2], clave: 'FFFFFFFFFFFF', tipoClave: 'A' },
    { sector: 6, bloques: [0,1,2], clave: 'FFFFFFFFFFFF', tipoClave: 'A' },
    { sector: 4, bloques: [0], clave: 'FFFFFFFFFFFF', tipoClave: 'A' }])
  .then((card) => {
    console.log(card)
    // returns Object {lectura: Array[3], card: "A3F813DB"}
  }).catch((err) => {
    console.log(err.message)
  })

  //writes multiple sectors and blocks but you must provide card id
  writeTag([{ sector: 5, bloques: [ 
   { indice: 1, data: [15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,15,15] },
   { indice: 2, data: [15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,15,15] } ],
    clave: 'FFFFFFFFFFFF', tipoClave: 'A' },
    { sector: 6, bloques: [ 
   { indice: 0, data: [15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,15,15] },
   { indice: 1, data: [15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,15,15] },
   { indice: 2, data: [15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,15,15] } ],
    clave: 'FFFFFFFFFFFF', tipoClave: 'A' },
   { sector: 4, bloques: [ 
   { indice: 0, data: [15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,15,15] } ],
    clave: 'FFFFFFFFFFFF', tipoClave: 'A' },
    ], "A3F813DB")
   .then((card) => {
     console.log(card)
   }).catch((err) => {
     console.log(err.message)
   })
...
```

## Configuration

In your manifest add:
```xml
<uses-permission android:name="android.permission.NFC" />
....
```
Your main activity should look like
```xml
...
<activity
  android:name=".MainActivity"
  android:launchMode="singleTask"
  android:label="@string/app_name"
  android:configChanges="keyboard|keyboardHidden|orientation|screenSize">

  <intent-filter>
    <action android:name="android.nfc.action.TECH_DISCOVERED"/>
  </intent-filter>

  <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
             android:resource="@xml/nfc_tech_filter" />
</activity>
```

Add a xml file in res folder with the following:
```xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  <tech-list>
    <tech>android.nfc.tech.MifareClassic</tech>
  </tech-list>
</resources>
```

## Contribution
Contributions are welcome :raised_hands:

## License
This repository is distributed under [MIT license](https://github.com/Lube/nfc-react-native/blob/master/LICENSE)

---
_Source: https://npm.io/package/nfc-react-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
