invalidate
TypeScriptinvalidate(): voidSwift declarationfunc invalidate()Invalidate session; emulation will be stopped immediately if it is still running. A new `CardSession` instance is required to restart.
class · iOS 17.4+ · SDK 27.1
class CardSessionISO7816 card emulation session. This is the session to allow ISO7816-4 protocol communication, send and receive Application Protocol Data Units (APDUs), with a NFC reader. To use this session: 1. Instantiate a new `CardSession` object. This will start the `eventStream`; `.sessionStarted` will be posted when the session becomes active. Once the session is started `Event.readerDetected` event will be generated when an external NFC field is detected. Optionally you may call `startEmulation()` to immediately start the card emulation regardless if an NFC reader is present. 2. Wait for `Event.readerDetected` to detect the presence of an external NFC reader. 3. Call `startEmulation()` when you app is ready to handle APDUs sent by the reader. This is when card emulation is enabled and reader can be connected to the device. 4. When `Event.received()` is received, process the APDU data, generate a response, and send it out using `APDU.respond(response:)`. If you don't send out the response, reader may detect a timeout conditions and generates error condition. 5.`Event.readerDeselected` is triggered when reader's field is turned off or device is pull away from the reader. 6. Call `invalidate()` to terminate the session. At any time `stopEmulation(status:)` can be called to stop card emulation (after emulation has been started previously). Note that stopping emulation at the wrong time can cause RF tearing and triggers error on the reader. NOTES: - Session is valid up to 60 seconds starting from the first`startEmulation()` call. Once this timeout occurs, `sessionInvalidated(reason: .maxSessionDurationReached)` will be returned from the event stream and the session will be invalidated. - A modal UI with text controlled by `alertMessage` will be shown on top of your app after `startEmulation()` is called. It will get dismissed when `stopEmulation(status:)` is called or session is invalidated. - `systemNotAvailable` indicates system is currently unavailable to accept your request; this is a temporal condition and you may retry the operation in a later time. - Special entitlement is required to use this service. As part of this entitlement you are required to declare a list of ISO7816 application identifiers (AID) prefixes that your application will be listen on when receiving the SELECT command from the reader. A `fatalError()` will occur on `CardSession.init()` if the necessary entitlement is missing. - `isEligible` can be used to determined if system is eligible to use the card session before instantiation. - `isSupported` shall be used to determine if the device supports NFC card session functionality. `fatalError()` will get triggered when `CardSession.init()` is called on unsupported hardware.
invalidate(): voidSwift declarationfunc invalidate()Invalidate session; emulation will be stopped immediately if it is still running. A new `CardSession` instance is required to restart.
static get isEligible(): Promise<boolean>Swift declarationstatic var isEligible: Bool { get async }Query system eligibility for using card session. You may want to query this result before calling `CardSession.createSession()` to avoid any system UI overlay to be shown.
get eventStream(): CardSession_EventStreamSwift declarationvar eventStream: CardSession.EventStream { get }Event stream for CardSession events.
static get isSupported(): booleanSwift declarationclass var isSupported: Bool { get }Return if current device supports card session functionality. CardSession APIs shall not be used if this returns false.
get alertMessage(): stringSwift declarationvar alertMessage: String { get set }Descriptive text message that is displayed on the alert action sheet once card emulation has started. The string can be updated dynamically in any thread context as long as the session is valid. This should be set prior to calling `startEmulation()` to display the correct message. Use this string to provide additional context about the NFC card emulation process.
set alertMessage(value: string)Swift declarationvar alertMessage: String { get set }Descriptive text message that is displayed on the alert action sheet once card emulation has started. The string can be updated dynamically in any thread context as long as the session is valid. This should be set prior to calling `startEmulation()` to display the correct message. Use this string to provide additional context about the NFC card emulation process.
stopEmulation(status: CardSession_EmulationUIStatus): Promise<void>Swift declarationfunc stopEmulation(status: CardSession.EmulationUIStatus) asyncStop emulation.
startEmulation(): Promise<void>Swift declarationfunc startEmulation() async throwsAttempt to start card emulation; will throw if unable to start. Upon success, a modal UI will be shown on top of your application.
get isEmulationInProgress(): Promise<boolean>Swift declarationvar isEmulationInProgress: Bool { get async }Return status of card emulation.
static init(): Promise<CardSession>Swift declarationinit() async throwsRequest to start a card session. Successful session start depends on the following conditions: - Device eligibility for using card session. - User has accepted your app request to use card session. Refer to `CardSession.Error` on possible errors. `fatalError()` will get triggered if `isSupported` returns false.
No declarations were skipped in this snapshot.