'iOS 11 CoreNFC How To Check if device has NFC Capability?

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.



Solution 1:[1]

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:

Weak Linking of Core NFC framework

and then check for Core NFC availability in code:

var isNFCAvailable: Bool {
    if NSClassFromString("NFCNDEFReaderSession") == nil { return false }
    return NFCNDEFReaderSession.readingAvailable
}

If isNFCAvailablereturns true then you can use all the APIs provided by Core NFC without worrying about your app crash.

Solution 2:[2]

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
}

Solution 3:[3]

Can check the device list from Apple https://developer.apple.com/support/required-device-capabilities/ (it's long, use: cmd-f + "nfc")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Legonaftik
Solution 2 Matt
Solution 3 tontonCD