Core NFC is an exciting new framework that enables you to read NFC tags in your apps on iPhone 7 and iPhone 7 Plus. Learn how to integrate Core NFC into your apps, key requirements for using this feature, and start thinking about the new kinds of apps that are enabled with NFC capabilities.
This year, we are delighted to introduce a new framework in iOS 11 called Core NFC, that would allow your apps to integrate NFC on iPhone 7 and iPhone 7 Plus.
Using Core NFC, apps can interact with their physical environment and the real-world objects within it.
You may already know that Apple Pay uses NFC for complex payment.
Now, with the introduction of Core NFC, you will be able to use NFC in your applications to create new and innovative user experiences with the iPhone.
In this session, we will give you a brief overview of new field communications, what is supported in the Core NFC framework, the requirements and details for using it, and some example code.
To start off, let's talk a little bit about Near Field Communication. Near Field Communication, known simply as NFC, is a wireless technology that allows the exchange of information between devices that are within close proximity.
Limited to a range of just a few centimeters.
NFC is actually a collection of a number of different standards and protocols.
All of these standards coexist and are used in different applications.
You may have seen or had experience with NFC text.
The small little stickers or cards which can be read wirelessly by an NFC reader.
NFC text comes in a wide variety of shapes, sizes, and capacities.
They are classified into five categories, known as Type 1 through Type 5.
Each one corresponding to a different standard.
For example, Type 3 texts are based on FEDECA [assumed spelling] and Type 4 is based on ISO-14443. The NFC Forum has defined the NFC Data Exchange Format, or NDEF for short, as a common messaging format for exchanging data in a standardized way among the different text types.
Now that we have covered some NFC basics, let's take a look at what you can do with Core NFC.
For the initial launch of Core NFC, we have focused on NFC Tag Reading, which can be used to enhance the user experience in a wide variety of ways.
Potential applications include connecting user to location or context-specific content, connecting physical hardware with your application, and even for in-store product information or inventory tracking.
In addition, NFC Tags can be used in place of QR codes. Core NFC will allow your application to read any NDEF formatted tag.
This greatly simplifies the process of reading tags within your application or for having to deal with the different standards.
Tag reading is supported on iPhone 7 and iPhone 7 Plus.
At this time, Core NFC does not support writing or formatting operations.
There are two requirements for using Core NFC in your application.
First, Core NFC is an entitlement-protective framework.
You will need to turn on the Near Field Communication Tag Reading Capability from Xcode to get this entitlement. However, this capability would not be in Xcode for the first released at WWDC. In the meantime, you can manually request this entitlement by visiting the Certificates, Identifiers and Profiles page on the Apple Developer website.
The second requirement for Core NFC is a Scan Usage Description.
This string is required in your application's info P-list file, and it will be displayed to the user when your application starts NFC scanning.
For more information, you can watch the WWDC session, Privacy and Your Apps.
Now that you have configured your project correctly, let's review some additional details about tag reading with the Core NFC framework.
First, tag reading is an on-demand process, meaning that your application has to initiate a tag reading activity using a session.
Second, your application has to be visible and foregrounded in order to start a tag reading activity.
A tag reading session will be ended if your application is backgrounded or ceases to be visible.
Next, each tag reading activity is limited to 60 seconds at a time. If a session has timed out or invalidated, your application must create a new session to initiate another tag reading activity.
You can configure a session to read either a single tag or multiple tags.
In a single tag reading mode, the session will be ended automatically after a tag is read.
On the other hand, a multi-tag reading session will remain active until canceled by the user, or the 60-second timeout is reached.
Finally, as mentioned previously, the NFC Usage String defined in your info P-list will be displayed to the user while the tag reading activity is in progress.
We have provided a sample application along with this presentation to demonstrate the use of Core NFC. Consider the case where you want to take a physical kind of inventory.
Here, we are showing you the key user interaction sequence of the sample application. The sample application consists of a main table view, and a Scan button.
Every time an inventory item is scanned, it is displayed as a role entry in this main table view.
Just click on the Scan button to start a tag scanning. This UI will be presented to the user hopefully on top of your application once tag scanning has begun.
During tag scanning, the user's description string is displayed within the UI.
At any time, the user can hit the Cancel button to stop a tag scanning, which will invalidate the reader session.
The UI will get updated once an NFC tag has been successfully read.
Here, we have configured our reader session to be single tag read mode.
Finally, the overlaid UI will be dismissed, and the application will be foregrounded once the tag reading session has ended.
All right. Let's walk through the code together from the sample application we have just shown.
At a high level, you would need to perform these three easy steps to enable tag reading in your application.
First, adopt the NFC NDEF Reader Session Delegate Protocol.
Next, create an instance of the NFC NDEF Reader Session Class, and provide it with your delegate.
Finally, start a reader session using the Begin method, and handle the delegate callbacks.
Here is a cool snippet from the sample application, illustrating the three-step approach.
To start off, we import the Core NFC framework into the code.
Here we adopt the delegate protocol in Table View Controller, which will handle the two required callbacks.
They invalidate with error and detect NDEF.
The invalidate with error callback will notify your application when a tag reading activity has stopped.
This can happen for a variety of reasons.
For example, a tag has been successfully read in a single tag read session.
The user has chosen to stop the tag scanning activity. The 3-second timeout has expired or the application is no longer in the foreground.
The specific session object provided in the first parameter will be invalidated after the function exits.
A new reader session instance is required for additional tag reading.
The detect NDEFs will be invoked every time an NDEF has been read from an NFC tag.
Your application can then grab the payload from the NDEF message, decode it, and handle the message as appropriate.
Finally, we have an extra method that links to the Scan button for starting a single tag read session.
All you need to do is create an instance of NFC NDEF Reader Session with your data gate, then invoke to begin method to start tag scanning.
If you wish to create a multi-tag reading session, set the invalidate at the first read parameter to False.
If you need to stop an ongoing session programmatically, you can call the invalidate method.
This will trigger your invalidate with error callback, letting you know that the session has ended.
In summary, it is very simple to enable NFC tag reading with Core NFC by following these steps.
Enable the NFC tag reading capability.
Make sure your Scan Usage Description String is set in your info P-list.
Integrate the Core NFC framework in your code.
And start reading tags.
For more information about this presentation and our sample code, please visit this online link.
Also, here are some related sessions you might be interested in.
Privacy and Your Apps will discuss important privacy-related topics, and What's New In Apple Pay and Wallet will talk about all the exciting Apple Pay features coming to iOS and Mac OS.
Thank you for watching this presentation on Core NFC Framework.
Looking for something specific? Enter a topic above and jump straight to the good stuff.
An error occurred when submitting your query. Please check your Internet connection and try again.