ios - NFCCore iOS 问题
问题描述
我使用 NFC 在 iOS 中开发了一个应用程序,但我总是收到错误 202,这意味着“意外错误”,但 Apple 没有提供有关此代码的任何信息。
我有:
- 在开发者 Apple 应用页面上启用 NFC
- 将 iPhone 7 与 iOS 11 一起使用
- 将 .entitlements 键 com.apple.developer.nfc.readersession.formats 设置为带有 NDEF 的数组
- 将 NFC 隐私密钥设置为 info.plist
- 编写管理 NFC 的代码(类似于此iOS CoreNFC - 类“NFTechnologyEvent”未加载或不存在)
类 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 是否为真。
还要确保将“隐私 - NFC 扫描使用说明”添加到 Info.plist
请查看以下苹果文档中的示例代码。https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app
推荐阅读
- keras - 是否可以在 keras 中针对多类分类问题进行持续训练?
- asp.net - 在服务器端 ASP.NET Core 上使用 Google Maps 受限 API 密钥
- javascript - 我们如何使用 NodeJs 编写 shell 脚本
- consul - 从 Consul kv 向 nomad 传递值
- ios - 如何在 Swift 中计算两个日期的天数 [相同日期应计为“I”天]
- git - 无法将代码推送到 gerrit git 存储库
- r - 从时间戳数据中提取日期和时间
- html - 我对第 n 个孩子有一些问题
- xcode - xcrun 通过 NSTask:如何以与终端相同的形式获取返回值?
- laravel - 与 RESTful 相比,GraphQL GET 响应时间很慢