NFCCore iOS问题

问题描述 投票:0回答:1

[我使用NFC在iOS中开发了一个应用,但是我总是得到错误202,表示“意外错误”,但Apple没有提供有关此代码的任何信息。

我有:

  1. 在Developer Apple应用程序页面上启用NFC
  2. 在iOS 11上使用Iphone 7
  3. 使用NDEF将设置的权利密钥com.apple.developer.nfc.readersession.formats格式化为数组
  4. 将NFC隐私密钥设置为info.plist
  5. 编写代码以管理NFC(类似于此iOS CoreNFC - class "NFTechnologyEvent" not loaded or does not exist

TPNfcReaderViewController类:UIViewController {

var nfcSession: NFCNDEFReaderSession!
func startScanning(){
    nfcSession = NFCNDEFReaderSession(delegate: self, queue: DispatchQueue.main, invalidateAfterFirstRead: false)
    nfcSession.alertMessage = "You can hold you NFC-tag to the back-top of your iPhone"
    nfcSession.begin()
}
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    startScanning()
}

扩展名TPNfcReaderViewController:NFCNDEFReaderSessionDelegate {

func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
    print("Error reading NFC: \(error.localizedDescription)")
    //session.invalidate()
    //self.startScanning()
}
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
    //Never called
}

}

但是我总是得到

    connection to service named com.apple.nfcd.service.corenfc: Exception caught during decoding of received message, dropping incoming message.
Exception: Exception while decoding argument 0 (#2 of invocation):
Exception: decodeObjectForKey: class "NFTechnologyEvent" not loaded or does not exist

您有任何建议吗?

ios nfc
1个回答
0
投票

在调用session.begin()方法之前,您必须检查NFCNDEFReaderSession.readingAvailable true。

还请确保将“隐私-NFC扫描使用说明”添加到Info.plist中

[请从下面的Apple文档中查看示例代码。 https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app

© www.soinside.com 2019 - 2024. All rights reserved.