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

8.2k views Asked by At

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.

4

There are 4 answers

7
Paulw11 On BEST ANSWER

You can use the readingAvailable class property:

if NFCNDEFReaderSession.readingAvailable {
    // Set up the NFC session
} else {
    // Provide fallback option
}
0
Matt On

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
}
4
tontonCD On

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

0
Legonaftik On

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.