Search by

pushinbr / pam-native-nfc

DavidWilliamBalbino

Lifecycle-safe NDEF reading and writing for PAM Native on Android and iOS.

Package info

github.com/push-in/pam-native-nfc

Language:Swift

Type:pam-native-plugin

pkg:composer/pushinbr/pam-native-nfc

Statistics

Installs: 213

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-08-23 18:02 UTC

This package is auto-updated.

Last update: 2026-11-09 16:33:34 UTC


README

pam-native-nfc: Read and write NDEF tags through one lifecycle-safe API on Android and iOS.

Read and write NDEF tags through one lifecycle-safe API.
Run bounded NFC sessions, parse typed records and handle platform capability differences without leaking native session objects.

Packagist Latest release PHP 8.5 CI License

Install · Quick example · Platforms · Permissions · API · Issues

Install

Inside a PAM Native project, add only this capability:

pam composer require pushinbr/pam-native-nfc
pam doctor --fix

New to PAM? Follow the five-minute PAM Native setup once (pam init my-app --template native), then come back here. Your application stays a normal Composer project with a committed lockfile; pam doctor --fix refreshes the generated native integration. Use pam packages to inspect availability.

Quick example

use Pam\Native\Nfc\{NdefRecord, Nfc, NfcAvailability, NfcEvent, NfcEventKind};

$nfc = new Nfc();

$nfc->availability(function (NfcAvailability $availability) use ($nfc): void {
    if ($availability === NfcAvailability::Available) {
        $nfc->beginRead(fn (bool $ok, ?string $error) => null);
    }
});

$nfc->write(NdefRecord::uri('https://pam.dev'), fn (bool $ok, ?string $error) => null);

$nfc->poll(function (array $events): void {
    foreach ($events as $event) { /** @var NfcEvent $event */
        if ($event->kind === NfcEventKind::TagDiscovered) {
            handleRecords($event->records); // list<NdefRecord>
        }
    }
});

Only one NFC session may be active at a time. iOS presents the system NFC sheet and requires the NFC capability in the signing profile. Android uses reader mode and requires a foreground Activity. The queue is bounded to 128 events. NDEF payloads are limited to 1 MiB in PHP before reaching native code; the physical tag's capacity is checked at write time.

Platform support

Platform Support Notes
Android API 26+ Android NFC reader mode; foreground Activity required
iOS 15.0+ Core NFC system sheet; NFC entitlement required
PAM Native 0.8.0 to < 2.0.0 From pam-native.plugin.json; PHP 8.5+

Permissions and requirements

Platform Declared by the plugin
Android android.permission.NFC
iOS NFCReaderUsageDescription ("Allow this app to scan the NFC tags you choose."), entitlement com.apple.developer.nfc.readersession.formats = NDEF, TAG (ios/App.entitlements)

The iOS signing profile must include the NFC Tag Reading capability, and scanning needs a compatible physical device.

What you can build

  • Asset and inventory tagging
  • Contactless onboarding and pairing
  • Smart posters, tickets and physical experiences
Best for A focused capability you can add to any PAM Native application
Native path Android NFC · Core NFC
Application model Composer package + generated native integration
Design rule Independent module; no feed, vertical or application template bundled

API guide

API Responsibility
Nfc availability(), beginRead(), write() (1 to 128 records), poll() (up to 128 events), cancel().
NdefRecord NdefRecord::uri() and NdefRecord::text(); MIME and external records through the constructor (tnf, type, id, payload).
NfcEvent / NfcEventKind Typed TagDiscovered, WriteCompleted, Cancelled and Error events with their records.
NfcAvailability Available, Unavailable or Disabled.

All coded states, kinds and variants are sequential integer-backed enums. Use enum cases in application code; do not depend on raw wire numbers.

Production checklist

  • End sessions when the owning screen leaves the foreground.
  • Validate every record type, length and payload before use.
  • Treat tag data as untrusted external input.
  • Run pam doctor, pam test and a signed release build on every supported platform.
  • Exercise denial, cancellation, backgrounding, process restart and offline behavior before release.

Platform SDKs, credentials, entitlements, physical hardware and store configuration remain application responsibilities.

Troubleshooting

  • Session will not start: only one session may be active.
  • iOS cannot scan: verify the NFC entitlement and a compatible signed device.
  • Write fails: compare the encoded payload with the physical tag capacity.
  • Native integration is stale: run pam doctor --fix, rebuild the native host and inspect the first reported diagnostic.

Docs

Part of the PAM ecosystem

PAM

PAM runs PHP natively on servers, desktops and phones. This repository is one piece of it.

PAM PAM Desktop PAM Native Ecosystem
the runtime and CLI native desktop apps in PHP native Android and iOS apps in PHP every official package and plugin

Docs: push-in.github.io/pam-docs · Issues

Apache License 2.0 · Made in Brazil by Pushin