Skip to content

yanngodeau/SimplyNFC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SimplyNFC

Simply read and write NFC tags with iPhone (iOS 14.0+)

GitHub license Platform Swift

Installation

Swift package manager

Go to File | Swift Packages | Add Package Dependency... in Xcode and search for ยซย SimplyNFCย ยป

Cathage

You can use Carthage to install SimplyNFC by adding it to your Cartfile.

github "yanngodeau/SimplyNFC"

Manual

  1. Put SimplyNFC repo somewhere in your project directory.
  2. In Xcode, add SimplyNFC.xcodeproj to your project
  3. On your app's target, add the SimplyNFC framework:
    1. as an embedded binary on the General tab.
    2. as a target dependency on the Build Phases tab.

Usage

Read tag

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")
   }
}

Write on tag

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")
   }
}

Contribute

  • 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

License

SimplyNFC is distributed under the MIT License.

Author

Based on code by @tattn