NFC Reading on iOS 11 in 4 easy steps

With the launch of iOS 11 Apple start open us the use of the NFC on iOS. For the moment it is only possible to read content.

iOS new features with NFC reader mode

For the moment you need to go the Certificates, Identifiers & Profiles page (https://developer.apple.com/account/ios/identifier/bundle) to add manually the NFC capability to your app.

NFC tag reading capability on Dev center

And add this to the entitlments of your app:

In a next Xcode version, Apple will include directly inside your the capabilities tab on your Xcode project.

As you do for location usage descriptions or photo access, you need to add a string that describe the usage that your app will do with the NFC this description string will be showed to the user.
So add a string for the key: “Privacy — NFC Scan Usage Description” to your Info.plist.

Privacy — NFC Scan Usage Description” in Info.plist

You can copy this extension and paste it into your code just remember to update it with your class name.

Wrapping all together

I wrote this simple class to wrap all logic inside on class that you can easily incorporate into your app, I called it NFCScanner.

To call the scanner inside your app just do something like this:

That’s it! Now you can read NFC Tags with iOS. Note that there are some limitations: the scan session it is limited to 60 seconds and only runs in the foreground.

Troubleshooting: CoreNFC only works on iPhone 7 and iPhone 7 Plus and if you try to build against an iPhone Simulator, the CoreNFC framework will not be found.

You can find the example project here: https://github.com/barrault01/nfc_example

I write Swift code. Dad of two awesome children with a wonderful wife. Currently Head of Mobile @ Guru Investimentos

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store