17

我正在深入研究 iOS 13 的新 CoreNFC 功能,并且正在努力让 NFCTagReaderSession 正常工作。在设置我的权利并实例化 NFCTagReaderSession 和委托后,我尝试通过调用来启动会话nfcTagReaderSession?.begin()。我的会话立即因此错误而失效:

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

我按照此处的文档获取我的权利文件:https ://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_nfc_readersession_formats

我还在我的 Info.plist 中添加了适当的“隐私 - NFC 扫描使用说明”。

有没有人让这个工作呢?这只是 Xcode 11 或 iOS 13 的问题吗?

这是我的 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)")
    }
}

这是我的权利文件:

<?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>
4

4 回答 4

13

我遇到了同样的问题,但是在功能中删除并添加近场通信标签读取后它就消失了。

我的权利文件有一点不同:

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

但我不认为这是它。

此外,您可以尝试修改 Apple 示例以满足您的需求:https ://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app

或者只需从轮询选项中删除.iso18092 即可。我认为这个标准需要特定的权利。

于 2019-06-05T12:22:25.120 回答
5

信息列表像这样将此键添加到info.plist

<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>
于 2019-06-07T06:14:53.543 回答
4

要读取电子护照,除了在 Capabilities 中添加近场通信标签读取之外,您还需要在 info.plist 中添加以下 AID 键和值:

<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>A0000002471001</string>
</array>
于 2019-06-08T00:36:27.087 回答
1

您必须将此键添加到 info.plist:

NFC 标签读取器会话的 ISO7816 应用标识符

NFC 标签阅读器会话的 ISO18092 系统代码

我不知道这样做的价值。我做了一个项目示例,但我无法从我的电子护照中读取任何内容。星期五会有一个活动,我希望一切都会变得清晰:链接

于 2019-06-05T08:39:04.157 回答