swiftnfccore-nfcios13

"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>

Solution

  • 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.