How do you implement an NFC scanner that can read and write to NFC tags using SwiftUI?

1.7k views Asked by At

I want to add an NFC Reader and Writer to an app I am developing in SwiftUI. I can't find any resources on accomplishing this using SwiftUI. Any resources on doing this would be much appreciated. Thank you!

1

There are 1 answers

0
Seb Jachec On

NFC reading and writing logic should be independent of what you use to construct the view layer of your app – whether that's UIKit or SwiftUI doesn't matter.

Check out the documentation for the Core NFC framework, which allows for reading and writing NFC tags, and check other iOS NFC questions/answers on Stack Overflow, as this question has been asked before.

The Core NFC framework presents a native system interface to read/write to NFC tags on your behalf, without requiring you to implement any UI specifically.

iOS 11 Core NFC - any sample code?

Apple also have a sample project and somewhat of a guide: https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app

If you structured your app such that each view has a view model class containing logic relating to that view, you might choose to start the appropriate NFC reader/writer session in a button press handler function or perhaps when your view appears. You should be able to implement the appropriate delegate callback methods your view model class.