[我使用NFC在iOS中开发了一个应用,但是我总是得到错误202,表示“意外错误”,但Apple没有提供有关此代码的任何信息。
我有:
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
您有任何建议吗?
在调用session.begin()方法之前,您必须检查NFCNDEFReaderSession.readingAvailable true。
还请确保将“隐私-NFC扫描使用说明”添加到Info.plist中
[请从下面的Apple文档中查看示例代码。 https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app