UNPKG

je_nfc_sdk

Version:

A comprehensive React Native SDK for NFC-based device control and communication

46 lines (45 loc) 1.54 kB
// logic/NfcService.ts import NfcManager, { NfcTech } from 'react-native-nfc-manager'; import { Platform } from 'react-native'; import LoggerService from '../utils/LoggerService'; export const NfcService = { async checkNfcSupport() { const supported = await NfcManager.isSupported(); const enabled = supported ? await NfcManager.isEnabled() : false; LoggerService.log(`NFC Supported: ${supported}, Enabled: ${enabled}`); return { supported, enabled }; }, async scanTag() { await NfcManager.start(); await NfcManager.requestTechnology(NfcTech.IsoDep); const tag = await NfcManager.getTag(); LoggerService.log(`Tag: ${JSON.stringify(tag)}`); return tag; }, async sendApdu(apdu, timeoutMs = 5000) { return Promise.race([ NfcManager.transceive(apdu), new Promise((_, reject) => setTimeout(() => reject(new Error('⏰ NFC transceive timeout')), timeoutMs)) ]); }, async test() { return '✅ SDK Test Function Called Successfully'; }, async stop() { await NfcManager.cancelTechnologyRequest(); }, extractTagInfo(tag) { const info = {}; if (tag.id) info.id = tag.id; if (tag.techTypes) info.techTypes = tag.techTypes; if (Platform.OS === 'android') { if (tag.atqa) info.atqa = tag.atqa; if (tag.sak) info.sak = tag.sak; } return info; } };