Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Missing required entitlement" for NFCTagReaderSession

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>
like image 738
Steven Berard Avatar asked Jun 05 '19 02:06

Steven Berard


2 Answers

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.

like image 93
Stanislav K. Avatar answered Sep 25 '22 21:09

Stanislav K.


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>
like image 34
Eilgnaw Avatar answered Sep 24 '22 21:09

Eilgnaw