Reputation: 6515
I am looking to update my app and build with xCode 11.0.
I had NFC already implemented prior to iOS13 and I want to continue reading tags from devices with iOS11 and up. I don't need to write tags at this time and I don't need to constantly poll. I just want to listen on button press and invalidate my session after read.
My code works on a device with iOS12 but when I use my iOS13 device, the session gets invalidated immediately and I don't see the inbuilt pop indicating it was listening.
[CoreNFC] 00000002 815b8b00 -[NFCNDEFReaderSession beginSession]:318 error:Error Domain=nfcd Code=2 "Busy" UserInfo={NSLocalizedDescription=Busy}, errorCode: 0xcb
The session was invalidated: System resource unavailable
I have Near Field Communication Tag Reading turned on in my signing and capabilities.
I also have this turned on for my app identifier in the member center. I read that you may need to toggle the NFC switch off and on in the member center and re download the provisioning profile. I have done this many times here and also locally in my own project. I've tried to let xCode manage my certs and downloaded them manually.
My entitlements file has the following:
com.apple.developer.nfc.readersession.formats NDEF TAG
My VC implementing nfc contains:
import CoreNFC
import os
@available(iOS 11.0, *)
class NFC_VC: UIViewController
{
var nfcSession: NFCNDEFReaderSession?
override func viewDidLoad()
{
super.viewDidLoad()
configureAppearance()
logViewLoad()
nfcSession = NFCNDEFReaderSession.init(delegate: self, queue: nil, invalidateAfterFirstRead: true)
nfcSession?.begin()
}
}
@available(iOS 11.0, *)
extension NFC_VC: NFCNDEFReaderSessionDelegate{
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
print("The session was invalidated: \(error.localizedDescription)")
}
@available(iOS 11.0, *)
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
self.nfcSession?.invalidate()
}
}
Upvotes: 1
Views: 770
Reputation: 1
@available(iOS 11.0, *)
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
self.nfcSession?.invalidate()
}
try to replace self.nfcSession?.invalidate()
with session.invalidate()
Upvotes: 0