How does one detect if an iPhone has the ability to use the NFC chip provided by the core NFC framework?
I know right now it only works on iPhone 7 and 7 plus but I don't want to hardcode hardware string identifiers as I don't know what devices will come out in the future.
If you need details just to be sure, here's the whole list of iPhones that are NFC-enabled: iPhone 13, iPhone 13 Mini, iPhone 13 Pro, iPhone 13 Pro Max. iPhone 12, iPhone 12 Mini, iPhone 12 Pro, iPhone 12 Pro Max. iPhone 11, iPhone 11 Pro, iPhone 11 Pro Max, iPhone SE (2nd Gen)
If your phone screen changes and says “Ready to Scan”, you have NFC capabilities. If your phone shows an error message that says “Your phone is not equipped with NFC capabilities” this means you do not have the ability to scan in or out of the gated lots. iPhone SE models have a 'Background Tag Reading' feature.
With the release of iOS 13, iPhones finally have full access to NFC Tag features. With this new feature, iPhones apps can write NDEF information such as URLs and text. iPhones also enjoy native tag access to take advantage of features available on different NFC chips.
Update for iOS 12:
1) If you want to run your app only for iPhone 7 and newer models you can add NFC requirement in Info.plist
:
<key>UIRequiredDeviceCapabilities</key>
<array>
// ... your restrictions
<string>nfc</string>
</array>
With this requirement only the devices with NFC will be able to download our app from App Store.
2) For iPhones older than iPhone 7 and for iPads support you have to also check if Core NFC
is available because it is not included for these devices. That is why you should link Core NFC
framework using Weak Linking:
and then check for Core NFC
availability in code:
var isNFCAvailable: Bool {
if NSClassFromString("NFCNDEFReaderSession") == nil { return false }
return NFCNDEFReaderSession.readingAvailable
}
If isNFCAvailable
returns true
then you can use all the APIs provided by Core NFC
without worrying about your app crash.
You can use the readingAvailable
class property:
if NFCNDEFReaderSession.readingAvailable {
// Set up the NFC session
} else {
// Provide fallback option
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With