update docs

This commit is contained in:
Dmitry Novotochinov 2019-05-02 22:25:25 +03:00
parent 69b84e8c99
commit e55c0ef1f8
No known key found for this signature in database
GPG Key ID: 43D1DAF5AD39C927
2 changed files with 25 additions and 13 deletions

View File

@ -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 `<uses-permission android:name="android.permission.NFC"/>` to `android/app/src/main/AndroidManifest.xml` to enable NFC permission.
5. Make sure `minSdkVersion` is 18 in `android/build.gradle`.
## Usage

View File

@ -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));
```