NFC API
安装
npm install @cutos/core
npm install @cutos/devices
引入依赖
import {CoreAPI} from '@cutos/core';
import {DeviceNFC} from '@cutos/devices';
DeviceNFC
构造函数, 创建NFC设备实例
let devNFC = new DeviceNFC(name);
- name: NFC设备名称
举例:
devNFC = new DeviceNFC('demo-nfc');
DeviceNFC.init
NFC设备初始化
devNFC.init(callback);
- callback: 回调函数
举例:
devNFC.init((result, error) => {
if (!error) {
console.log('onDeviceCreate', result)
} else {
console.log(error)
}
});
DeviceNFC.connect
连接NFC
devNFC.connect(callback);
- callback:回调函数
举例:
devNFC.connect((result) => {
if (result.status) {
console.log('connect success:', result)
} else {
console.log('connect failed:', result.msg)
}
});
DeviceNFC.onData
接收NFC信息
DeviceNFC.onData(callback)
- callback:回调函数
举例:
DeviceNFC.onData((data) => {
console.log('data', data)
})
- 返回结果示例:
{
"id": "110111201"
}