Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 292
SolidSnake4444 Avatar asked Aug 28 '17 03:08

SolidSnake4444


People also ask

Does iPhone 11 have NFC support?

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)

How do I know if my iPhone supports NFC?

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.

Is NFC available on iOS?

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.


2 Answers

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.

like image 98
Legonaftik Avatar answered Nov 10 '22 01:11

Legonaftik


You can use the readingAvailable class property:

if NFCNDEFReaderSession.readingAvailable {
    // Set up the NFC session
} else {
    // Provide fallback option
}
like image 35
Paulw11 Avatar answered Nov 10 '22 01:11

Paulw11