New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trentrand/capacitor-nfc

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trentrand/capacitor-nfc

Capacitor plugin to scan NFC tags

0.3.0
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
0
Weekly downloads
 
Created
Source

@trentrand/capacitor-nfc

Capacitor plugin to scan NFC tags

Install

npm install @trentrand/capacitor-nfc
npx cap sync

Xcode project prerequisites

iOS Configuration

Attempting to use this plugin on iOS without proper configuration in Xcode will result in an immediate app crash when NFCNDEFReaderSession.begin() is called. To prevent this:

  • Enable NFC capabilities in Xcode and configure entitlements

    • In Xcode, click on your project in the navigator
    • Select your target
    • Click "Signing & Capabilities"
    • Click "+ Capability"
    • Add "Near Field Communication Tag Reading"
    • Verify the entitlements file now contains:
      <key>com.apple.developer.nfc.readersession.formats</key>
      <array>
          <string>TAG</string>
      </array>
      
  • Add NFC usage description to Info.plist

<key>NFCReaderUsageDescription</key>
<string>Describe why your app needs NFC access</string>
  • Ensure your Apple Developer account has NFC capabilities enabled in the Apple Developer portal. This requires a paid membership.

API

  • startScan(...)
  • stopScan()
  • write(...)
  • isEnabled()
  • addListener('nfcTagRead', ...)
  • removeAllListeners()
  • Interfaces

startScan(...)

startScan(options?: NFCScanOptions | undefined) => Promise<void>

Start scanning for NFC tags.

ParamTypeDescription
optionsNFCScanOptionsOptional scan configuration

stopScan()

stopScan() => Promise<void>

Stop scanning for NFC tags.

write(...)

write(options: NFCWriteOptions) => Promise<void>

Write data to an NFC tag.

ParamTypeDescription
optionsNFCWriteOptionsWrite configuration including the records to write

isEnabled()

isEnabled() => Promise<{ enabled: boolean; }>

Check if NFC is available and enabled on the device.

Returns: Promise<{ enabled: boolean; }>

addListener('nfcTagRead', ...)

addListener(eventName: 'nfcTagRead', listenerFunc: (event: NFCReadEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Add a listener for NFC events.

ParamTypeDescription
eventName'nfcTagRead'Name of the event to listen for
listenerFunc(event: NFCReadEvent) => voidCallback function

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for NFC events.

Interfaces

NFCScanOptions
PropType
timeoutnumber
NFCWriteOptions
PropType
recordsNFCRecord[]
timeoutnumber
NFCRecord
PropType
recordTypestring
mediaTypestring
dataDataView
DataView
PropType
bufferArrayBuffer
byteLengthnumber
byteOffsetnumber
MethodSignatureDescription
getFloat32(byteOffset: number, littleEndian?: boolean | undefined) => numberGets the Float32 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getFloat64(byteOffset: number, littleEndian?: boolean | undefined) => numberGets the Float64 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getInt8(byteOffset: number) => numberGets the Int8 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getInt16(byteOffset: number, littleEndian?: boolean | undefined) => numberGets the Int16 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getInt32(byteOffset: number, littleEndian?: boolean | undefined) => numberGets the Int32 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getUint8(byteOffset: number) => numberGets the Uint8 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getUint16(byteOffset: number, littleEndian?: boolean | undefined) => numberGets the Uint16 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
getUint32(byteOffset: number, littleEndian?: boolean | undefined) => numberGets the Uint32 value at the specified byte offset from the start of the view. There is no alignment constraint; multi-byte values may be fetched from any offset.
setFloat32(byteOffset: number, value: number, littleEndian?: boolean | undefined) => voidStores an Float32 value at the specified byte offset from the start of the view.
setFloat64(byteOffset: number, value: number, littleEndian?: boolean | undefined) => voidStores an Float64 value at the specified byte offset from the start of the view.
setInt8(byteOffset: number, value: number) => voidStores an Int8 value at the specified byte offset from the start of the view.
setInt16(byteOffset: number, value: number, littleEndian?: boolean | undefined) => voidStores an Int16 value at the specified byte offset from the start of the view.
setInt32(byteOffset: number, value: number, littleEndian?: boolean | undefined) => voidStores an Int32 value at the specified byte offset from the start of the view.
setUint8(byteOffset: number, value: number) => voidStores an Uint8 value at the specified byte offset from the start of the view.
setUint16(byteOffset: number, value: number, littleEndian?: boolean | undefined) => voidStores an Uint16 value at the specified byte offset from the start of the view.
setUint32(byteOffset: number, value: number, littleEndian?: boolean | undefined) => voidStores an Uint32 value at the specified byte offset from the start of the view.
ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.

PropTypeDescription
byteLengthnumberRead-only. The length of the ArrayBuffer (in bytes).
MethodSignatureDescription
slice(begin: number, end?: number | undefined) => ArrayBufferReturns a section of an ArrayBuffer.
PluginListenerHandle
PropType
remove() => Promise<void>
NFCReadEvent
PropType
messageNFCMessage
serialNumberstring
NFCMessage
PropType
recordsNFCRecord[]

Keywords

capacitor

FAQs

Package last updated on 21 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts