Streaming is available in most browsers,
and in the WWDC app.
Core NFC Enhancements
Learn how easy it is to add support for NFC in your app and take advantage of the newest capabilities such as NDEF writing and support for widely adopted native tag protocols.
- Core NFC
- CoreNFC Tag Reading
- Creating NFC Tags from Your iPhone
- Presentation Slides (PDF)
Hi. Welcome to Core NFC Enhancements. I hope everyone's had a great WWDC this year. And I hope everyone had a great time at the bash yesterday. My name is Gordon. I'm a member of the NFC Software team here at Apple. A little bit later, we'll bring up another team member, Lawrence. But let's talk NFC.
So two years ago, we introduced the Core NFC framework to enable NDEF Tag reading within your applications. And last year, we introduced background tag scanning to support the automatic discovery of NDEF Tags and application launching. Now, however, since -- ever since we've launched the Core NFC Framework, developers have been asking for one specific thing. And here at Apple, we've listened to your requests. And this year, we are super excited to announce support for both NDEF Tag writing and native tag access. So yep, thank you. So not only will your applications be able to read and write NDEF-formatted tags, but you'll be able to interact with tags using their native protocols. And this has a huge impact on the kinds of things you can do with NFC within your applications. For example, you can read passports, contact with smart cards, and interact with NFC-enabled hardware. And all this is available on iPhone 7 and later phones.
So after we review the API changes, we'll take a look at how to write an NDEF tag within your applications.
Then we'll dive into using native tag access.
And finally, end up with a demo showing all of this in action.
So let's take a look at the new API changes.
As a quick review, the general structure of the Core NFC Framework remains the same as it does today. Your applications will retrieve a reader session object from the Framework. And when that session becomes active, you're free to go ahead and perform NFC operations.
The tag-reading action sheet will still be shown on-screen anytime a reader session is active.
And the new tag writing and native tag access features are available to your applications. However, the background tag scanning feature still requires NDEF formatted tags and is read-only.
Also, the existing 60-second maximum scan time still exists for each reader session.
So what is new? So this year, there's a new NFC tag-reader session which will allow your applications to scan for and connect to tags based on their underlying technologies. It will also allow you to stop and restart the polling cycle to discover new tags or to reconnect if needed.
Also, the NFCNDEFReaderSession has been modified to also support tag writing. Now, both of these sessions will provide your applications with NFC tag objects, allowing you to use a new tag-based interface when interacting with tags.
So here's a quick look at the new tag protocols in Core NFC. As you can see, there are protocols for all the major types. NDEF, ISO7816, MIFARE, ISO15693, and FeliCa. Now, if you're not familiar with all the various NFC technologies, I would suggest focusing first on NDEF.
So let's go over the basic steps of how to use these new features in Core NFC. First, you'll need to enable the entitlement in Xcode, just as you do today.
So here's an example of an application enabling the NFC capabilities. There are no special permissions required to do this. And as you can see here, there are two different capabilities, one for NDEF, and one for native tag access.
So next, you'll need to decide what your application requires, NDEF or native access, and use the appropriate reader session.
You'll need to implement the new protocol delegate callbacks to receive the new tag objects.
Once you have the tag object, you use the reader session to go ahead and connect to the tag.
At that point, you're free to go ahead and perform all your interactions using the tag object.
And finally, when you're done, invalidate the session and release your tag.
All right. So as I mentioned, if you're new to NFC, start first with the NFC Data Exchange Format, or NDEF. It is the easiest way to add NFC capabilities to your applications. The new tag running support allows for quick implementation and prototyping using any -- NDEF-formatted tag regardless of its type. As an example, an NDEF tag can be used in the same manner as a QR code and can easily be integrated into many existing use cases. To extend that even further, using the new tag-writing support in NFC, you can create NFC tags that are compatible with background tag scanning directly from iOS. So let's take a look. Yeah. Thank you. Let's take a closer look at just how simple it is to write an NDEF tag within your application. So as I noted, you'll need to use the NFCNDEFReaderSession for this. And you'll need to implement the new didDetect tags callback method to receive the NDEF tag objects. This will allow your application to do various things, such as query the NDEF-related information about the tag, including its maximum capacity, and determine whether the tag is writeable or not. You'll be able to read the NDEF message, write the NDEF message. And if the tag supports it, even lock the tag so that it can no longer be rewritten. So let's take a look at some code. To start writing an NDEF tag, we instantiate our NFCNDEFReaderSession. We provided our new delegate. And we set the invalidateAfterFirstRead parameter to false.
Next, when a tag is discovered, we receive it in our new Delegate callback method here.
Once we have a tag, we then send it to the reader session's Connect method to go ahead and connect to the tag. Now at this point, your tag will remain connected until you either connect to a different tag, restart polling, or invalidate your session.
So the next step here, after we've connected to the tag, we go ahead and query the NDEF information. If the tag returns a read-write status, then we're free to go ahead and write a new message to the tag.
So the next step here. We create an NFC NDEF message with our payload and then send it to the tag's writeNDEF method to update the tag.
Finally, when we're all done, we call the invalidate method. This will terminate all NFC operations and end our session. And that's it. Pretty simple, right? This is all it takes to write an NDEF tag within your app. Now there might be some use cases where you need to interact with tags that are not NDEF formatted. And for that, we'll need to go ahead and use native tag access. So let's dive into that.
We'll start first with ISO7816. The ISO7816 interface is used in Type A and Type B NFC tags. And it's used in a variety of different use cases, including electronic IDs such as passports, access, contact with smart cards, payments, and transit systems. Tags that support 7816 utilize the Application Protocol Data Unit interface. This is commonly referred to as APDU. And your applications will be able to send and receive APDU commands using the 7816 tag objects.
Now there are a few special requirements for interacting with 7816 tags. So let's go over those first before we look at some code.
First, your application will need to add an entry into its info.plist file that declares the specific application identifiers, or AIDs, which your application intends to use.
Next, once Core NFC has discovered a tag, it will first check to see if that tag supports an AID listed in your application's info.plist file. It does this by trying to select each AID in turn until it finds a match. At that point, the Delegate callback will be invoked, and you will receive the tag object with that AID preselected. However, at this point, you're free to go ahead and select any other AID listed in your info.plist file.
Now, we're excited about these new features in Core NFC. However, for the time being, reading payment cards will not be supported.
So here's an example of an application info.plist file listing the AIDs it intends to use.
Here, you can see the application is listing the AID for NDEF operations.
So now, we'll take a look at the actual 7816 tag object. The protocol has properties that are specific to the 7816 technology. You can see the attributes here include the unique identifier and the historical bytes. So is anyone excited about the unique ID here? This is the second-most popular request that we get. There's also a sendCommand method for transmitting any form of APDU to the tag and receiving the response.
So to start scanning the 7816 tags, as I mentioned, the first thing that we'll need to do is implement a Delegate object which conforms to the NFCTagReaderSession Delegate protocol. There are only three required methods, and you can see them up here.
So to start scanning for 7816 tags, we instantiate our NFCTagReaderSession object, provide it our delegate, and set the polling option to ISO14443. This is the underlying NFC technology for Type A and Type B tags.
Next, when Core NFC discovers a tag that has a matching AID, we receive it in our Delegate callback.
And once we're assured that we have a 7816 tag, we use the reader's session.connect method to go ahead and connect to the tag.
And finally, after we're connected, we create an APDU using the helper class and use the same command method of the tag to transmit the APDU and receive its response.
Now during the transaction, we may find an application-related error has occurred, and we should not continue. As an example, imagine we're trying to read a passport. And it turns out we don't have the proper credentials, or we've calculated the password incorrectly. In a scenario like this, we would really like to indicate this error to the user. Calling the Invalidate method with an error message will invalidate the session, and an error symbol, along with the supplied error message, will be shown on the action sheet UI rather than a checkmark.
So here's an example of what this error indication looks like. We'll see this later in the demo. But this is pretty great, right? This is the third-most requested feature we get. And just for reference, here's the existing success indication.
So that was 7816. Let's move on to our second technology, MIFARE. MIFARE is the technology similar to 7816. And it's based on NFC Type A tags. MIFARE is a technology defined by NXP and is used heavily in ticketing and badging systems throughout the world.
So the NFC MIFARE tag protocol has properties similar to that of 7816. In addition, there's another property of the MIFARE family. This will indicate the specific MIFARE tag type that has been discovered. It can be MIFARE Ultralight, MIFARE Plus, or DESFire. At this time, MIFARE Classic tags are not supported. There's also a method here for sending any MIFARE command. In addition, there's a convenience method for sending 7816 APDUs for those tags, such as DESFire and Plus, which will support them.
So now, let's see this in action.
Just start scanning for a MIFARE tag. We again instantiate our tag reader session. Again, we set our polling option to ISO14443. And we set the Delegate and Call Begin.
Please note that a MIFARE tag that supports a 7816 interface and contains an AID listing the applications info.plist file will instead be returned as a 7816 object and not a MIFARE object.
So at this point, when our callback gets invoked, we specifically check to make sure that we have a MIFARE tag object returned.
Once we're sure we have one, we send it to the reader's session.connect method and connect to the tag. And then use the tag to send a MIFARE command.
Okay, so that's two of the four technologies. So let's look at ISO15693. This is also known as type five or vicinity tags. And these are commonly used in retail, industrial, and even medical applications.
So once again, this protocol has properties specific to the ISO15693 technology. Here, we also have the unique identifier, as well as the manufacture code and the serial number.
And the command set for 15693, if you have not seen it, is quite large. And the protocol has convenience methods for some of the common operations. You can see them listed up here. They cover reading and writing single or multiple blocks, locking blocks, select, and reset. Again, there's also a method for sending any custom command. You can construct any command according to the ISO15693 specification and use that method to send it. You can go ahead and refer to the specification for more details.
So to start scanning for vicinity tags, which should now be looking very familiar to everyone, we create our NFCTagReaderSession, provide it our delegate. But this time, we changed the polling option to ISO15693.
When Core NFC discovers a 15693 tag, again, we receive the tag in our callback.
We again verify that we have the proper tag type and then connect to it using the sessions.connect method.
And once connected, we use the tag to issue a readSingleBlock command.
So finally, we're on to our fourth and final technology, FeliCa. FeliCa is a format defined by Sony, and it's used heavily in transit and payment systems around Japan.
Now the FeliCa usage also has some additional requirements. Similar to 7816, your application will need to add an entry into the info.plist file that declares the specific FeliCa system codes your application intends to use. And for security and privacy reasons, we're asking that these be discreet FeliCa system codes and not wildcard entries.
Again, similar to 7816, when Core NFC discovers a FeliCa tag, we'll first validate -- detect that that tag contains a system code listed in your info.plist file. If it does, you'll receive the tag and the Delegate callback. If it does not, the callback does not get invoked, and your application does not get notified about the presence of the tag.
So here's an example of an info.plist file registering for FeliCa system code reserved for NDEF operations.
Again, taking a look at the FeliCa tag protocol here, we see properties specific to FeliCa. We have the manufacturer ID, or IDM, and the current selected system code. Also, there's a sendFeliCaCommand method for sending any FeliCa command to the tag.
And this protocol also has convenience methods for some of the common FeliCa operations. You can go ahead and refer to Sony's FeliCa command specification for more details.
So continuing what should now be a very familiar usage model, we instantiated an NFCTagReaderSession, provide it our delegate, and this time, changed the polling option to ISO18092, which is the NFC technology for FeliCa.
So once Core NFC has discovered a tag and found a matching system code, we again receive the tag object in our same delegate.
We ensure that we have the proper tag type we were expecting and then connect to the tag.
And then finally, we use the tag to send a requestResponse command. So we've now covered NDEF tag writing and interacting with tags using all four of the native technologies.
So at this point, I'm going to bring Lawrence onstage and show us a demo of all of this in action. All right, thank you, Gordon. Hello, everyone. Welcome.
To demonstrate how Core NFC Framework can be used in a real-life example, let me take you through a quick journey of my imaginary fishmonger.
As a tech savvy fishmonger, I have heard that the NFC technologies can improve customer engagement and also be used in inventory management. After listening on this great presentation, I have decided to create two applications to help my business, The Great Fish Company. I'm going to use NFC in two ways. First, I'm going to create NFC NDEF tags to describe my product. And second, I'm going to create coupon tags using MIFARE Ultralight tags, which is also known as NFC Type II tags.
Here is an overview of how we deliver our products. After we catch our fish, we integrate NFC NDEF tag to describe the catch. The message contains the fish they have catch, the fish name, and the price. The tag is then attached to the product packaging and eventually gets delivered to our customers. The first application that I'm going to create is called the Fish Tag Creator. This is what it looks like here.
Once I've entered all the information into my app, I can click on the Write to Tag button to write to the NDEF tag. The Fish Tag Creator application also allows me to create NFC coupon codes to promote my business. I use a MIFARE Ultralight tag to store the special coupon code and send it to my customers. Here, I can select one of the three possible coupon values to write. The second application that I create is called a Fish Tag Reader. My customer will be able to download this app from the App Store to read the NDEF fish tag that come with their purchase. In the first panel, we have the Click Scan button to scan the fish tag that comes with the fish. The app would then display the information stored it on the tag. In the second panel, we can click on the Scan Coupon button to read our MIFARE Ultralight fish tag -- coupon tags. Customer can redeem this coupon in their future purchase. Now let's take a look at both of these apps in actions.
All right. I have basically put the -- the Fish Tag Reader app right -- creator app right now. Today I brought with me a creative rainbow salmon with me. Let me first select today's dates and the fish name, which is Creative Salmon. Okay, this one is definitely the large size, right? So now I click on the Write to Tag button. The action sheet will be shown. And now, at this point, I can hold my phone near the NDEF tag.
Now let me next then create a coupon tag for your audience here. I'm going to select Create Coupon button.
I'm going to choose a 50% off since, you know, this is a special WWDC promotion, right? All right, so let's click on the button. The action sheet again will be shown on the screen. And now, I can hold my iPhone near the coupon tag.
Voila! Okay, so now let's switch over to the NFC Tag Readers app to retest all my NFC tags.
Here, I have the app open. I'm going to press on the Scan Tag button and read my NDEF fish tag.
The description of the product is now displayed on the screen. Wow, that's cool. Alright. Now let me try to scan the coupon tag. This is done by selecting the second panel and clicking on the Scan Coupon button.
All right, yeah. This is the fish 50% off coupon. Okay, so now let me try to read the second coupon again.
Okay, this is not a valid coupon. So after seeing both of these are running in actions, let me switch over to the source code and take a look at how this is implemented.
All right, let's walk through the Fish Tag Creative Offers.
Here, I'll set the NDEF and native tag capabilities in my entitlement file. This is because I'm going to use both the NDEF and tag readings -- reader session in my application.
Now let's take a look at the Main View controller to see how they NDEF writer is being implemented.
In the -- Sorry, one second here.
In the Write Tag Action function, we have to instantiate an NFCNDEFReaderSession. We set the alert message and call the Begin Method to start a session.
When an NDEF tag is found, it is going to be sent to the Delegate function. We connect to the tag and call queryNDEFStatus. If the tag is writeable and has sufficient storage, we call the writeNDEF function to write to the tag. Finally, we call the invalidateFunction to end the session.
Now let's take a look how a coupon is created.
Here, we have the createCoupon action function. We instantiate a TagReaderSession object. We call the setAlert message and call beginFunction to start a session.
Here, we are looking specifically for a MIFARE Ultralight coupon tag in the Delegate function. When a tag is actually found, we connect to it and start the write operation.
To write to the tag, we basically create a coupon code and then call sendMIFARE command to start a write operation. When all write operations are completed, we invalidate the session.
We have used both NDEF and native tag reader session to create NFC tags. Now let's take a look together with the Fish Tag Reader app.
The NFCTagReaderSession has convenience methods to perform NDEF operations.
This is what we use here. However, it's required us to add the 7816 AID and Type F system code into the -- for the NDEF in our info.plist file, which is shown here.
Now in the Scan View controller -- We have the scan tag action function. Here, we create a TagReaderSession, set the alert message, and call begins to start the -- write the Reader action function.
When an NFC tag is found, it is then delivered to our Delegate callback.
We connect to the tag and perform NDEF status query.
If the tag is readable, we call readNDEF method.
Now let's -- finally, we actually invalidate the session by calling Invalidate.
Now let's take a look how we read a coupon tag.
Here, we have a ScanCoupon action function. And just like before, we instantiate a NFCTagReaderSession object. We set the alert message. And we start a session by calling the Begin.
When a tag is found, we check to see if it's a MIFARE Ultralight tag. If it is, we connect to the tag.
To read from the tag, we call the sendMIFARE command.
We then validate the queue point.
At the end, we call the Invalidate method to end the session.
If the coupon is invalid, we call invalidateErrorMessage instead.
Now that's everything that you need in order to create a great app using the Core NFC Framework. Back to Gordon. Thank you, Lawrence.
So we hope the new tag writing and native access allows you to add awesome new features to your applications. As we've seen, it's pretty straightforward and pretty simple. Let's do a quick review of what we've gone over today. First, decide which type of reader session your application has required. NDEF, native access, or even both.
Implement the newDelegate methods to receive the new tag objects. Once you have those tag objects, go ahead and perform all your reads and writes using those objects. And when you're all done, indicate the proper success or error indication using the appropriate Invalidation call.
And that's it.
So all the sample code that we have gone through today is available to you online now, along with other information. iOS 13 is available now along with Xcode 11. Everybody should go ahead download that and use Core NFC to start doing awesome, new things. And if anybody has questions, the Core NFC Lab is immediately following this session over in the labs. So come talk to us and say hello. [ Cheering and Applause ]
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.