iOS 11 CoreNFC How To Check if device has NFC Capability?
You can use the readingAvailable
class property:
if NFCNDEFReaderSession.readingAvailable {
// Set up the NFC session
} else {
// Provide fallback option
}
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.
Also check devices with iOS < 11.0 ie. iPhone 5
import CoreNFC
.
.
// Check if NFC supported
if #available(iOS 11.0, *) {
if NFCNDEFReaderSession.readingAvailable {
// available
}
else {
// not
}
} else {
//iOS don't support
}