pub struct Nfc<R: Runtime>(/* private fields */);Expand description
Access to the nfc APIs.
Implementations§
Source§impl<R: Runtime> Nfc<R>
impl<R: Runtime> Nfc<R>
Sourcepub fn is_available(&self) -> Result<bool>
pub fn is_available(&self) -> Result<bool>
Checks whether NFC is supported by the device and currently usable by the app.
On Android this is false when the device has no NFC adapter or when NFC is
disabled in the device settings.
On iOS this is false when the NFCReaderUsageDescription entry is missing from the
Info.plist file or when NFC tag reading is not available on the device.
Sourcepub fn scan(&self, payload: ScanRequest) -> Result<ScanResponse>
pub fn scan(&self, payload: ScanRequest) -> Result<ScanResponse>
Scans an NFC tag, blocking until a tag matching the given ScanRequest::kind filters
is read or the scan fails.
Set ScanRequest::keep_session_alive to true to keep the connection to the tag open
after it has been scanned, so that a following Self::write call writes to that tag.
§Errors
Returns an error when NFC is not available (see Self::is_available)
or when the tag could not be read.
Sourcepub fn write(&self, records: Vec<NfcRecord>) -> Result<()>
pub fn write(&self, records: Vec<NfcRecord>) -> Result<()>
Writes the given NDEF records to an NFC tag, blocking until the write completes or fails.
Because this API does not take a scan kind, on Android it can only write to the tag of an
ongoing session, so it must be preceded by a Self::scan call with
ScanRequest::keep_session_alive set to true.
On iOS an NDEF reader session is started when there is no ongoing session, and the
records are written to the first tag that is scanned.
§Errors
Returns an error when NFC is not available (see Self::is_available), when there is no
connected tag on Android, when the tag is read-only, when it cannot hold the message or
when it does not support the NDEF format.