iOS NFC Reader ============== 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 (:js:class:`SCWS.createEnvironment`) and the device supports NFC Tag Reader Session, a :js:class:`Reader` named ``NFC Interface`` will be added to the list of the readers (:js:class:`SCWS.readers`). To get the NFC (:js:class:`Reader`), call (:js:class:`SCWS.getReader`) by passing ``NFC Interface`` as parameter. For (:js:class:`Reader`) objects with :js:class:`Reader.requiresNfcTagReaderSession` returns ``true``, you must use the functions below. To start scanning for NFC Tags, call (:js:class:`SCWS.initNfcTagReaderSession`). iOS will display an alert action sheet waiting to detect tags. When a tag is detected, your app will receive a (:js:class:`SCWS.onreaderstatechanged`) event. When your app is done communicating with the card or if an error occurred, call (:js:class:`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. .. js:autofunction:: SCWS.initNfcTagReaderSession .. js:autofunction:: SCWS.endNfcTagReaderSession .. js:autofunction:: SCWS.updateMessageNfcTagReaderSession Android similar behavior example -------------------------------- To have a similar behavior on Android and iOS, a mechanism similar to the alert action sheet on iOS must be implemented. For each call of (:js:class:`SCWS.initNfcTagReaderSession`), (:js:class:`SCWS.endNfcTagReaderSession`) and (:js:class:`SCWS.updateMessageNfcTagReaderSession`) on iOS, an alert action sheet must be displayed on Android. Here is an example of how it can be done. Detecting when NfcTagReaderSession are required ''''''''''''''''''''''''''''''''''''''''''''''' The boolean :js:class:`Reader.requiresNfcTagReaderSession` can indicate if the iOS NFC Tag Reader Session functions are required: .. code-block:: js function nfcTagReaderSessionRequired() { return (SCWS.getReader("NFC Interface") && SCWS.getReader("NFC Interface").requiresNfcTagReaderSession); } } Initialization of the NFC session ''''''''''''''''''''''''''''''''' To initialize the NFC session, an dialog overlay can be displayed to reproduce iOS behavior: .. code-block:: js function initNfcSession(message) { window.scanning = true; if (nfcTagReaderSessionRequired()) // iOS SCWS.initNfcTagReaderSession(message); else // Android displayOverlay(); } Where displayOverlay() shows a dialog that indicates that NFC scanning is on: .. code-block:: js function displayOverlay() { document.getElementById("overlay").style.display = "block"; } With **overlay** defined in the html body: .. code-block:: HTML