迅速:NFCError Code = 202“会话意外地无效". [英] Swift: NFCError Code=202 "Session is invalidated unexpectedly"
问题描述
我正在尝试使用NFC.我遵循了这些步骤:
I'm trying to use NFC. I followed those steps:
-
在AppID配置中启用了NFC
Enabled NFC in the AppID configuration
创建了配置文件并安装了它
Created a provisioning profile and installed it
为目标添加了NFC功能
Added NFC capability to the target
在plist文件中添加了隐私说明
Added the privacy description in the plist file
此后,我导入了CoreNFC并实现了这些代码:
After this I imported CoreNFC and implemented those code:
@available(iOS 11.0, *)
extension EventPreviewViewController: NFCNDEFReaderSessionDelegate {
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
let alert = UIAlertController.withOkButton(andTitle: NSLocalizedString("TitleWarning"), andText: NSLocalizedString("ErrorNFCInvalidate"), okHandler: nil)
self.present(alert, animated: true, completion: nil)
}
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
// TODO
}
}
class EventPreviewViewController: UITableViewController {
@available(iOS 11.0, *)
var nfcSession: NFCNDEFReaderSession {
return NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: true)
}
@IBAction func startAccess(_ sender: UIButton) {
if #available(iOS 11.0, *) {
nfcSession.begin()
} else {
let alert = UIAlertController.withOkButton(andTitle: NSLocalizedString("TitleWarning"), andText: NSLocalizedString("ErrorNFCUnsupported"), okHandler: nil)
self.present(alert, animated: true, completion: nil)
}
}
}
为什么我不断收到错误域= NFC错误代码= 202会话意外失效" UserInfo = {NSLocalizedDescription =会话意外失效}"?
Why I keep getting "Error Domain=NFCError Code=202 "Session is invalidated unexpectedly" UserInfo={NSLocalizedDescription=Session is invalidated unexpectedly}"?
推荐答案
针对ios13/swift 5.1的更新
update for ios13 / swift 5.1
a)苹果公司的原始样本有时会失败,并导致相同的错误.
a) original sample from Apple does sometimes fails the same error.
( https://developer.apple.com/documentation/corenfc/building_an_nfc_tag- reader_app )
b)如果失败(似乎是愚蠢的.无论如何..都可以工作.)重新启动设备.它发生了;(
b) if fails (seems a be stupid.. anyway.. works..) reboot device. It happens ;(
这篇关于迅速:NFCError Code = 202“会话意外地无效".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!