"Missing required entitlement" for NFCTagReaderSession
Asked Answered
R

4

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>
Roee answered 5/6, 2019 at 2:23 Comment(1)
Almost the same as you are on nfciso15693tag. see:<#57000888>Carnotite
R
17

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.

Readjust answered 5/6, 2019 at 12:22 Comment(9)
I removed . iso18092 but doesn't read iso14443 tags. Any suggestion?Romo
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?Roee
@Byteros, no, I completely forgot that my passport has NFC tag. Try to do it later.Readjust
@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.Readjust
@StevenBerard I can read Mifare tags, without remove iso18092 from polling list but I cannot read the passport. I Don't know why...Romo
@Romo I can't read ePassports too, it looks like it isn't even detecting the NFC chip of itUstkamenogorsk
@Romo I found the solution for the ePassport. Take a look here: https://mcmap.net/q/666209/-cannot-read-the-nfc-chip-of-the-epassport-using-ios13Ustkamenogorsk
@StevenBerard I can not read Mifare too with an iPhone 7. I try with an ePassport and its ok but no Mifare tags.Doha
Is it possible to increase the timeout of NFCTagReaderSession? By default it is set to 20 seconds #58192248Birdie
A
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>
Aquarelle answered 7/6, 2019 at 6:14 Comment(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?Ustkamenogorsk
@JanMoritz try "ISO7816 application identifiers for NFC Tag Reader Session" "D2760000850101" and "ISO18092 system codes for NFC Tag Reader Session" "12FC"Aquarelle
I put it in the entitlements. My fault.Ustkamenogorsk
I also put it in the entitlements and got same error. Thanks for your fault.Recruit
I followed each step but I'm not able to run application in release mode. Am i missing something ? @RecruitKalman
M
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>
Maximilianus answered 8/6, 2019 at 0:36 Comment(2)
@JanMoritz We are two 😬Romo
I found that this worked in combination with <string>00000000000000</string> ref. https://mcmap.net/q/666209/-cannot-read-the-nfc-chip-of-the-epassport-using-ios13Showalter
R
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

Romo answered 5/6, 2019 at 8:39 Comment(7)
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.Roee
Why can't you read from the ePassport? Isn't it detecting the Tag?Ustkamenogorsk
@JanMoritz yes, tagReaderSession(didDetect:) callback is no fired with ePassport or eID. I've more lucky with Mifare tags.Romo
@Romo same for me using german ePassport/eID. Thank you for your answer.Ustkamenogorsk
@Romo twitter.com/maartenwegdam/status/1136220776485535746 apparently they were able to make it work. Perhaps we are doing something wrong.Ustkamenogorsk
@JanMoritz yes maybe.Romo
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.Ustkamenogorsk

© 2022 - 2024 — McMap. All rights reserved.