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"
SimplyNFC.xcodeproj
to your projectReading 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")
}
}
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
SimplyNFC is distributed under the MIT License.
Based on code by @tattn
link |
Stars: 21 |
Last commit: 6 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics