title: Taro.sendHCEMessage(option)

sidebar_label: sendHCEMessage

Sends NFC messages. It only works in the Android system.

Reference

Type

  1. (option: Option) => Promise<NFCError>

Parameters

Option

Property Type Required Description
data ArrayBuffer Yes Binary data
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

Sample Code

  1. const buffer = new ArrayBuffer(1)
  2. const dataView = new DataView(buffer)
  3. dataView.setUint8(0, 0)
  4. Taro.startHCE({
  5. success: function (res) {
  6. Taro.onHCEMessage(function (res) {
  7. if (res.messageType === 1) {
  8. Taro.sendHCEMessage({data: buffer})
  9. }
  10. })
  11. }
  12. })

API Support

API WeChat Mini-Program H5 React Native
Taro.sendHCEMessage ✔️