NFC-NFCAdapter
NFCAdapter
- Parameters and descriptions: Object tech, Tag type enumeration
Properties Type Description ndef String Corresponding to the Ndef instance, the instance supports reading and writing NDEF data on NFC tags in NDEF format nfcA String Corresponding to the NfcA instance, the instance supports reading and writing of the NFC-A (ISO 14443-3A) standard nfcB String Corresponding to the NfcB instance, the instance supports reading and writing of the NFC-B (ISO 14443-3B) standard isoDep String Corresponding to the IsoDep instance, the instance supports reading and writing according to the ISO-DEP (ISO 14443-4) standard nfcF String Corresponding to the NfcF instance, the instance supports reading and writing of the NFC-F (JIS 6319-4) standard nfcV String Corresponding to the NfcV instance, the instance supports reading and writing of the NFC-V (ISO 15693) standard mifareClassic String Corresponding to the MifareClassic instance, the instance supports reading and writing MIFARE Classic tags mifareUltralight String Corresponding to the MifareUltralight instance, the instance supports reading and writing MIFARE Ultralight tags
.startDiscovery
TIP
The API usage is as follows: NFCAdapter.startDiscovery()
Parameters and descriptions: Object object。
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Error code
Error code Error message Description 13000 The device does not support NFC - 13001 The system NFC switch is not turned on - 13010 Unknown error - 13019 user is not authorized The user is not authorized 13011 invalid parameter Invalid parameters 13012 parse NdefMessage failed Failed to parse parameters into NdefMessage 13021 NFC discovery already started NFC scanning has started 13018 NFC discovery has not started Attempt to stop NFC scanning when NFC scanning has not started 13022 Tech already connected The tag is already connected 13023 Tech has not connected Attempt to disconnect when the tag is not connected 13013 NFC tag has not been discovered NFC tag not scanned 13014 invalid tech Invalid tag technology 13015 unavailable tech Failed to obtain the corresponding technology from the tag 13024 function not support The current tag technology does not support this function 13017 system internal error Related read and write operations failed 13016 connect fail Connection failed
.stopDiscovery
TIP
The API usage is as follows: NFCAdapter.stopDiscovery()
Parameters and descriptions: Object object。
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Error code
Error code Error message Description 13000 The device does not support NFC - 13001 The system NFC switch is not turned on - 13010 Unknown error - 13019 user is not authorized The user is not authorized 13011 invalid parameter Invalid parameters 13012 parse NdefMessage failed Failed to parse parameters into NdefMessage 13021 NFC discovery already started NFC scanning has started 13018 NFC discovery has not started Attempt to stop NFC scanning when NFC scanning has not started 13022 Tech already connected The tag is already connected 13023 Tech has not connected Attempt to disconnect when the tag is not connected 13013 NFC tag has not been discovered NFC tag not scanned 13014 invalid tech Invalid tag technology 13015 unavailable tech Failed to obtain the corresponding technology from the tag 13024 function not support The current tag technology does not support this function 13017 system internal error Related read and write operations failed 13016 connect fail Connection failed
.getNdef
TIP
The API usage is as follows: Ndef NFCAdapter.getNdef()
- Functional description: Get Ndef instances, which support reading and writing NDEF data on NFC tags in NDEF format
- Return value: Ndef。
.getNfcA
TIP
The API usage is as follows: Ndef NFCAdapter.getNfcA()
- Functional description: Get an NfcA instance, which supports reading and writing the NFC-A (ISO 14443-3A) standard
- Return value: NfcA。
.getNfcB
TIP
The API usage is as follows: NfcB NFCAdapter.getNfcB()
- Functional description: Get an NfcB instance, which supports reading and writing the NFC-B (ISO 14443-3B) standard
- Return value: NfcB。
.getNfcF
TIP
The API usage is as follows: NfcF NFCAdapter.getNfcF()
- Functional description: Get an NfcF instance, which supports reading and writing the NFC-F (JIS 6319-4) standard
- Return value: NfcF。
.getNfcV
TIP
The API usage is as follows: NfcV NFCAdapter.getNfcV()
- Functional description: Get an NfcV instance, which supports reading and writing the NFC-V (ISO 15693) standard
- Return value: NfcV。
.getIsoDep
TIP
The API usage is as follows: IsoDep NFCAdapter.getlsoDep()
- Functional description: Get an IsoDep instance that supports reading and writing the ISO-DEP (ISO 14443-4) standard
- Return value: IsoDep。
.getMifareClassic
TIP
The API usage is as follows: MifareClassic NFCAdapter.getMifareClassic()
- Functional description: Get the MifareClassic instance, which supports reading and writing MIFARE Classic tags
- Return value: MifareClassic。
.getMifareUltralight
TIP
The API usage is as follows: MifareUltralight NFCAdapter.getMifareUltralight()
- Functional description: Get the MifareUltralight instance, which supports reading and writing MIFARE Ultralight tags
- Return value: MifareUltralight。
.onDiscovered
TIP
The API usage is as follows: NFCAdapter.onDiscovered(function listener)
- Functional description: Monitor NFC Tag
- Parameters and descriptions: function listener,Listening function, the parameter Object res is as follows:
Properties Type Description id ArrayBuffer - techs Array tech array, used to match what standard (such as NfcA) can be used for NFC card processing messages Array NdefMessage array, the message format is {id: ArrayBuffer, type: ArrayBuffer, payload: ArrayBuffer}
.offDiscovered
TIP
The API usage is as follows: NFCAdapter.offDiscovered(function listener)
Functional description: Remove the listening function of NFC Tag
Parameters and descriptions: function listener,The listening function passed in by onDiscovered. If this parameter is not passed, all listening functions will be removed
Sample code:
const listener = function (res) { console.log(res) }
NFCAdapter.onDiscovered(listener)
NFCAdapter.offDiscovered(listener) // Pass the same function object used for listening.