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.
1) Enable NFC Tag Reading capability
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.
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.
2) Add NFC usage description to your 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.
3) Implement NFCNDEFReaderSessionDelegate
You can copy this extension and paste it into your code just remember to update it with your class name.
4) Start Scanning
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