Allow users to scan NFC tags without an app using background tag reading.
- Core NFC
On iPhones that support background tag reading, the system scans for and reads NFC data without requiring users to scan tags using an app. The system displays a pop-up notification each time it reads a new tag. After the user taps the notification, the system delivers the tag data to the appropriate app. If the iPhone is locked, the system prompts the user to unlock the phone before providing the tag data to the app.
To avoid unintentional tag reading, the system reads tags in the background only when the user’s iPhone is in use. Also, be aware there are times when the display is on and background tag reading is unavailable, such as if:
The device has never been unlocked.
A Core NFC reader session is in progress.
Apple Pay Wallet is in use.
The camera is in use.
Airplane mode is enabled.
Process Scanned Tags
After the device scans an NFC tag while in background tag reading mode, the system inspects the tag’s NDEF message for a URI record by looking for an
NFCNDEFPayload object with the following property values:
If the NDEF message contains more than one URI record, the system uses the first one. The URI record must contain either a universal link or a supported URL scheme.
Use Universal Links
For universal links, the system launches (or brings to the foreground) the app associated with the universal link after the user taps the notification. The system sends the NDEF message to the app as an
NSUser object. If there are no installed apps associated with the universal link, the system opens the link in Safari.
Use URL Schemes
The system processes NDEF payloads containing a URI for a URL scheme in the same way as universal links. The system displays a notification after reading the tag. When the user taps the notification, the system launches the app that supports the URL scheme.
Background tag reading supports the following URL schemes:
Website URL (HTTP/HTTPS)
HomeKit Accessory Setup
For more information on URL schemes, see Apple URL Scheme Reference.
Configure Your App
Add support for background tag reading to your app by turning on Associated Domains under the project’s Capabilities tab. This step adds the
Associated Domains Entitlement to your project’s entitlement file and to the app ID. Next, enter the domain for each universal link supported by your app.
Handle Tag Delivery
To handle the NDEF message read from the tag, implement the
application(_: method in your app delegate. The system calls this method to deliver the tag data to your app in an
NSUser object. The user activity has an
NSUser, and the tag data is available in the
For user activities not generated by background tag reading,
ndef returns a message that contains only one
NFCNDEFPayload record. That record has a
Not all devices support background tag reading, so be sure to provide the user the option to read tags directly from your app. For more information, see Building an NFC Tag-Reader App.