NCF communication

On iOS, NFC operations are restricted by the system. They can only be performed after a system call when a pop-up displayed on the screen. That is why specific API functions must be used to read tokens with NFC.

Using NFC readers on iOS

Note that iOS NFC Tag Reader Session is supported in: iPhone XR, iPhone X, iPhone XS, iPhone XS Max, iPhone 11, iPhone 11 Pro. (iOS 13)

If the creation of the environment was successful (SCWS.create()) and the device supports NFC Tag Reader Session, a Reader() named NFC Interface will be added to the list of the readers (SCWS.readers()).

To get the NFC (Reader()), call (SCWS.getReader()) by passing NFC Interface as parameter. For (Reader()) objects with Reader.requiresNfcTagReaderSession() returns true, you must use the functions below.

To start scanning for NFC Tags, call (SCWS.initNfcTagReaderSession()). iOS will display an alert action sheet waiting to detect tags. When a tag is detected, your app will receive a (SCWS.onreaderstatechanged()) event.

When your app is done communicating with the card or if an error occurred, call (SCWS.endNfcTagReaderSession()). It will end the NFC Tag Reader Session, dismiss the alert action sheet and display a message error or a positive check mark to the user.

SCWS.initNfcTagReaderSession(message)

Start scanning for NFC tags. After calling this function, iOS will display an alert action sheet wainting to detect tags.

Arguments
  • message – descriptive text message that is displayed on the alert action sheet once the scan is started. The string can be updated dynamically by calling SCWS.updateMessageNfcTagReaderSession().

Returns

A promised resolved when the operation completes. The resulting value is a string which can take the following values: - cancelled: The user cancelled the alert action sheet. - timeout: iOS cancelled the alert action sheet, because the user did not present a card within required time. - ok: The operation completed following a call to SCWS.endNfcTagReaderSession(). Note that before calling the following function, you need to check if the reader requires iOS NFC Tag Reader Session by calling Reader.requiresNfcTagReaderSession().

SCWS.endNfcTagReaderSession(message)

Closes the NFC Tag reader session and displays a feedback to the user. if the session was not successful, a message must be provided, which will be displayed to the user as an error. If the operation was successful, the message must be set to null and a positive check mark will be displaye to the user.

Arguments
  • messagenull if the session was successful, or a message error if the session was not successful. Note that before calling this function, you need to check if the reader requires iOS NFC Tag Reader Session by calling Reader.requiresNfcTagReaderSession().

SCWS.updateMessageNfcTagReaderSession(message)

Update the text message that was displayed on the alert action sheet of the NFC Tag Reader Session.

Arguments
  • message – the new text message to be displayed on the alert action sheet. Note that before calling this function, you need to check if the reader requires iOS NFC Tag Reader Session by calling Reader.requiresNfcTagReaderSession().

Similar behavior on Android

In order to have cross-platform code, a similar behavior can be achieved with the (AndroidNfcOverlay()) class.

For example code to implement cross-platform NFC reading code, see NFC Implementation Example.