Simply read and write NFC tags with iPhone (iOS 14.0+)
Go to File | Swift Packages | Add Package Dependency... in Xcode and search for « SimplyNFC »
You can use Carthage to install SimplyNFC by adding it to your Cartfile.
github "yanngodeau/SimplyNFC"- Put SimplyNFC repo somewhere in your project directory.
- In Xcode, add
SimplyNFC.xcodeprojto your project - On your app's target, add the SimplyNFC framework:
- as an embedded binary on the General tab.
- as a target dependency on the Build Phases tab.
Reading NCFNDEFMessage from tag
import SimplyNFC
let nfcManager = NFCManager()
nfcManager.read { manager in
// Session did become active
manager.setMessage("π Place iPhone near the tag to read")
} didDetect: { manager, result in
switch result {
case .failure:
manager.setMessage("π Failed to read tag")
case .success:
manager.setMessage("π Tag read successfully")
}
}Writing NFCNDEFMessage on tag
import SimplyNFC
let nfcManager = NFCManager()
nfcManager.write(message: ndefMessage) { manager in
// Session did become active
manager.setMessage("π Place iPhone near the tag to be written on")
} didDetect: { manager, result in
switch result {
case .failure:
manager.setMessage("π Failed to write tag")
case .success:
manager.setMessage("π Tag successfully written")
}
}- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
SimplyNFC is distributed under the MIT License.
- Yann Godeau - @yanngodeau
Based on code by @tattn