19

I'm diving into iOS 13's new CoreNFC capabilities, and I'm struggling to get NFCTagReaderSession working. After setting up my entitlements and instantiating an NFCTagReaderSession and delegate I attempt to start the session by calling nfcTagReaderSession?.begin(). My session immediately gets invalidated with this error:

Error Domain=NFCError Code=2 "Missing required entitlement" UserInfo={NSLocalizedDescription=Missing required entitlement}

I followed the documentation here for my entitlements file: https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_nfc_readersession_formats

I have also added the appropriate "Privacy - NFC Scan Usage Description" in my Info.plist.

Has anyone gotten this to work yet? Is this just a problem with Xcode 11 or iOS 13?

Here is the code in my ViewController:

import UIKit
import CoreNFC

class ViewController: UIViewController {

    var nfcTagReaderSession: NFCTagReaderSession?

    override func viewDidLoad() {
        super.viewDidLoad()

        nfcTagReaderSession = NFCTagReaderSession(pollingOption: [.iso14443, .iso15693, .iso18092], delegate: self)
        nfcTagReaderSession?.begin()
        print("isReady: \(nfcTagReaderSession?.isReady)")
    }
}

extension ViewController: NFCTagReaderSessionDelegate {
    func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
        print("Tag reader did become active")
    }

    func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
        print("\(error)")
    }

    func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
        print("\(tags)")
    }
}

Here is my entitlements file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.nfc.readersession.formats</key>
    <array>
        <string>TAG</string>
        <string>NDEF</string>
    </array>
</dict>
</plist>
Guilherme Matuella
  • 2,193
  • 1
  • 17
  • 32
Steven Berard
  • 193
  • 1
  • 1
  • 4

4 Answers4

14

I had the same problem, but it is gone after removing and adding Near Field Communication Tag Reading in Capabilities.

My entitlements file have a little differ:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:example.com</string>
    </array>
    <key>com.apple.developer.nfc.readersession.formats</key>
    <array>
        <string>NDEF</string>
        <string>TAG</string>
    </array>
</dict>
</plist>

But I don't think this is it.

Also, you can try to modify Apple example to fit your needs: https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app

Or just remove .iso18092 from polling options and it will work. I think this standard require specific entitlement.

Stanislav K.
  • 374
  • 4
  • 13
  • 1
    I removed . iso18092 but doesn't read iso14443 tags. Any suggestion? – Byteros Jun 05 '19 at 13:42
  • 3
    Removing .iso18092 worked! Thanks so much, Stanislav! I'm able to read standard iso14443 tags. I cannot, however, read the Mifare Classic variant of the iso14443 tags. Any idea if Apple is excluding the Mifare Classic on purpose? – Steven Berard Jun 05 '19 at 19:16
  • @Byteros, no, I completely forgot that my passport has NFC tag. Try to do it later. – Stanislav K. Jun 06 '19 at 05:18
  • 1
    @StevenBerard, I can not read the Mifare too. Still, don`t know how to make it work. Hope the Friday session clear something and they did not exclude this specification. – Stanislav K. Jun 06 '19 at 05:25
  • @StevenBerard I can read Mifare tags, without remove iso18092 from polling list but I cannot read the passport. I Don't know why... – Byteros Jun 06 '19 at 06:40
  • @Byteros I can't read ePassports too, it looks like it isn't even detecting the NFC chip of it – Jan Moritz Jun 06 '19 at 22:41
  • 1
    @Byteros I found the solution for the ePassport. Take a look here: https://stackoverflow.com/a/56516232/2652054 – Jan Moritz Jun 09 '19 at 16:11
  • @StevenBerard I can not read Mifare too with an iPhone 7. I try with an ePassport and its ok but no Mifare tags. – Kepa Santos Sep 17 '19 at 09:12
  • Is it possible to increase the timeout of NFCTagReaderSession? By default it is set to 20 seconds https://stackoverflow.com/questions/58191748/nfctagreadersession-has-timeout-of-20-seconds-how-to-increase-it – Naren Oct 01 '19 at 20:23
12

info.plistadd this keys to info.plist like this

<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>D2760000850101</string>
</array>
<key>com.apple.developer.nfc.readersession.felica.systemcodes</key>
<array>
    <string>12FC</string>
</array>
Display Name
  • 4,502
  • 2
  • 47
  • 63
Eilgnaw
  • 121
  • 5
  • How do you fix the resulting "Provisioning profile "JAN DEV" doesn't include the com.apple.developer.nfc.readersession.felica.systemcodes and com.apple.developer.nfc.readersession.iso7816.select-identifiers entitlements." error? – Jan Moritz Jun 07 '19 at 08:19
  • @JanMoritz try "ISO7816 application identifiers for NFC Tag Reader Session" "D2760000850101" and "ISO18092 system codes for NFC Tag Reader Session" "12FC" – Eilgnaw Jun 07 '19 at 09:10
  • 2
    I put it in the entitlements. My fault. – Jan Moritz Jun 07 '19 at 10:56
  • I also put it in the entitlements and got same error. Thanks for your fault. – muyoungko Jan 08 '23 at 04:10
  • I followed each step but I'm not able to run application in release mode. Am i missing something ? @muyoungko – Vanjara Sweta Apr 17 '23 at 16:16
6

To read ePassports, besides adding the Near Field Communication Tag Reading in Capabilities, you will need to add the following AID key and value in info.plist:

<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>A0000002471001</string>
</array>
Melvin
  • 61
  • 2
1

You have to add this keys to info.plist:

ISO7816 application identifiers for NFC Tag Reader Session

ISO18092 system codes for NFC Tag Reader Session

I don't know the value for this. I did an example of a project but I can't read anything from my ePassport. On Friday there will be an event where I hope that everything will become clear: link

Byteros
  • 123
  • 1
  • 17
  • Ya. I'm waiting with bated breath for the Friday session. I really wish I decided to go to San Jose this year to talk to the engineers. For now, I'm just removing the option to read ISO 18092 tags. – Steven Berard Jun 05 '19 at 19:18
  • Why can't you read from the ePassport? Isn't it detecting the Tag? – Jan Moritz Jun 06 '19 at 22:50
  • @JanMoritz yes, tagReaderSession(didDetect:) callback is no fired with ePassport or eID. I've more lucky with Mifare tags. – Byteros Jun 07 '19 at 07:29
  • @Byteros same for me using german ePassport/eID. Thank you for your answer. – Jan Moritz Jun 07 '19 at 08:02
  • @Byteros https://twitter.com/maartenwegdam/status/1136220776485535746 apparently they were able to make it work. Perhaps we are doing something wrong. – Jan Moritz Jun 07 '19 at 08:08
  • @JanMoritz yes maybe. – Byteros Jun 07 '19 at 12:05
  • The video is out and he keeps talking about reading the NFC chip of the passport in it. But still doesn't work for me. – Jan Moritz Jun 08 '19 at 13:04