From e55c0ef1f8148c1e9a7ccabc0b44691349462a8c Mon Sep 17 00:00:00 2001 From: Dmitry Novotochinov Date: Thu, 2 May 2019 22:25:25 +0300 Subject: [PATCH] update docs --- README.md | 7 +++++-- docs/usage.md | 31 ++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c5aa401..c3d8165 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Android is the only platform supported by now. #### Android -1. Open up `android/app/src/main/java/[...]/MainActivity.java` - - Add `import com.reactlibrary.RNStatusKeycardPackage;` to the imports at the top of the file +1. Open up `android/app/src/main/java/[...]/MainApplication.java` + - Add `import im.status.ethereum.keycard.RNStatusKeycardPackage;` to the imports at the top of the file - Add `new RNStatusKeycardPackage()` to the list returned by the `getPackages()` method 2. Append the following lines to `android/settings.gradle`: ``` @@ -30,6 +30,9 @@ Android is the only platform supported by now. ``` compile project(':react-native-status-keycard') ``` +4. Add `` to `android/app/src/main/AndroidManifest.xml` to enable NFC permission. + +5. Make sure `minSdkVersion` is 18 in `android/build.gradle`. ## Usage diff --git a/docs/usage.md b/docs/usage.md index 60bdf06..6767350 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -3,28 +3,28 @@ You need to import Keycard object to interact with the card: ```javascript -import { RNStatusKeycard as Keycard} from "react-native-status-keycard"; +import Keycard from "react-native-status-keycard"; ``` ### Listen to keycard connect/disconnect events ```javascript -import DeviceEventEmitter from "react-native"; +import { DeviceEventEmitter } from 'react-native'; // Listen to connect/disconnect events -DeviceEventEmitter.addListener("keyCardOnConnected", () => console.log("keycard connected")); -DeviceEventEmitter.addListener("keyCardOnDisconnected", () => console.log("keycard disconnected")); +componentDidMount () { + DeviceEventEmitter.addListener("keyCardOnConnected", () => console.log("keycard connected")); + DeviceEventEmitter.addListener("keyCardOnDisconnected", () => console.log("keycard disconnected")); +} ``` ### Errors -As library uses Promises for method calls, use `.catch` to get the error object. +Library uses Promises for method calls, use `.catch` to get the error object. Example: ```javascript -Keycard.getApplicationInfo(). -then(info => console.log(info)). -catch(error => console.log(error)) +Keycard.init("123456").then(info => console.log(info)).catch(error => console.log(error)) ``` Error object example: @@ -47,7 +47,13 @@ Keycard.openNfcSettings(); ### Get keycard information ```javascript -Keycard.getApplicationInfo().then(info => console.log(info)); +// If keycard was not paired before, use empty string as pairing +Keycard.getApplicationInfo("").then(info => console.log(info)); + +// If keycard is paired, use pairing key +const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo"; +Keycard.getApplicationInfo(pairing).then(info => console.log(info)); + ``` Returns object like this: @@ -77,9 +83,12 @@ Keycard.init(pin).then(secrets => console.log(secrets)); ``` ### Pair -Pairs keycard to device: +Pairs keycard to device. + +Use password you get after keycard initialization (using `init`): + ```javascript -const password = "/xzPt+rEWVN3sMc5" +const password = "/xzPt+rEWVN3sMc5"; Keycard.pair(password).then(pairing => console.log(pairing)); ```