I am using
Код: Выделить всё
CoreNFC
Код: Выделить всё
iOS
The problem I have is that sometimes i'll get successfully through my writes, but the majority of the time I get either of these errors:
Код: Выделить всё
Error Domain=NFCError Code=100 "Tag connection lost" UserInfo={NSLocalizedDescription=Tag connection lost}
Код: Выделить всё
Error Domain=NFCError Code=102 "Tag response error" UserInfo={NSLocalizedDescription=Tag response error, ISO15693TagResponseErrorCode=15}
Код: Выделить всё
Error Domain=NFCError Code=401 "Stack Error" UserInfo={NSLocalizedDescription=Stack Error, NSUnderlyingError=0x3017960d0 {Error Domain=nfcd Code=21 "writeNdefData:toTag:nLengthOptimization:error::403" UserInfo={Line=403, NSLocalizedDescription=Connection Closed, NSDebugDescription=writeNdefData:toTag:nLengthOptimization:error::403, Method=writeNdefData:toTag:nLengthOptimization:error:}}}
How can I find what
Код: Выделить всё
ISO15693TagResponseErrorCode=15
As an example of one of my writes, it's to completely erase the tag.
Код: Выделить всё
func erase(tag: NFCISO15693Tag) async throws { print("🏷️", "ERASING TAG") alertMessage = "ERASING TAG..." let sysInfo = try await getSystemInfo(from: tag) let totalBlocks = sysInfo.totalBlocks - 1 let blockSize = sysInfo.blockSize var blockNumber: UInt8 = 0 func writeNextBlock() async throws { if blockNumber < totalBlocks { alertMessage = "ERASING TAG \(blockNumber)/\(totalBlocks)" let blankData = Data(repeating: 0x00, count: blockSize) try await write(data: blankData, to: tag, at: blockNumber) // Move to the next block blockNumber += 1 try await writeNextBlock() } else { // All blocks have been erased alertMessage = "Tag erased successfully!" } } // Start writing to the first block try await writeNextBlock() } func write(data: Data, to tag: NFCISO15693Tag, at block: UInt8) async throws { print("🏷️", "Writing data:", data, data.hexEncodedString(.upperCase), "at block:", block) try await tag.writeSingleBlock(requestFlags: [.highDataRate], blockNumber: block, dataBlock: data) }
Код: Выделить всё
@MainActor private func eraseTag() { session = NFCTagReaderSession(pollingOption: [.iso15693], delegate: self, queue: nil) session?.alertMessage = "Hold your iPhone near a new NFC tag." session?.begin() } func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) { guard tags.count == 1 else { session.invalidate(errorMessage: "Can not write to more than one tag.") return } let currentTag = tags.first! guard case .iso15693(let iso15693Tag) = currentTag else { session.invalidate(errorMessage: "Tag is not iso15693") return } Task { do { try await session.connect(to: currentTag) print("Connected: ========\(currentTag.isAvailable)========") try await session.erase(tag: iso15693Tag) session.invalidate() } catch { print("❗️", error) session.invalidate(errorMessage: error.localizedDescription) } } }
I get the error sometimes when reading too, however if I use the NFC Tools app it manages to read the chip a lot more than my app can. Is there some additional parameters or setup I need? Or perhaps I have a threading issue?
Источник: https://stackoverflow.com/questions/781 ... eem-stable