【问题标题】:Missing required entitlement for NFCTagReaderSession缺少 NFCTagReaderSession 所需的权利
【发布时间】:2020-02-07 21:59:39
【问题描述】:

我正在尝试使用 ISO7816 通过 corenfc 启动通信,但我总是收到相同的错误,即使我尝试了在 Internet 上发布的多个请求。

代码是

@IBAction func scanPressed(_ sender: Any) {
        nfcSession = NFCTagReaderSession.init(pollingOption: .iso14443, delegate: self)
        nfcSession?.alertMessage = "Hold your IPhone near the ISO7816 tag to begin transaction.";
        nfcSession?.begin()
    }

我的 info.plist 是

<?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.iso7816.select-identifiers</key>
    <array>
        <string>D2760000850101</string>
    </array>
    <key>com.apple.developer.nfc.readersession.formats</key>
    <array>
      <string>NDEF</string>
      <string>TAG</string>
    </array>  
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NFCReaderUsageDescription</key>
    <string>Message in a Card</string>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
        <string>nfc</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

我收到以下错误

会话无效:Error Domain=NFCError Code=2 "Missing required entitlement" UserInfo={NSLocalizedDescription=Missing required entitlement}

如何解决?

【问题讨论】:

  • 解决了这个问题吗?

标签: ios swift iphone


【解决方案1】:

infos.plist中的“com.apple.developer.nfc.readersession.iso7816.select-identifiers”设置必须正确,AID设置错误会报错。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

您的权利应位于名为 NFCTagReaders.entitlements 的文件中,并且应包含以下内容:

<?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>NDEF</string>
        <string>TAG</string>
    </array>
</dict>

我不确定为什么在您的情况下它包含在主 Info.plist 文件中。 这可能与您的问题有关,因为您的配置看起来正确。

Info.plist 和 NFCTagReaders.entitlements 文件:

请同时检查项目配置中是否激活了 NFC 功能。

您还应该在开始会话之前通过添加以下行来检查 NFC 会话是否可用:

guard NFCTagReaderSession.readingAvailable else {
        print("NFC Session not available")
        return
    }

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多