I'm trying to read multiple blocks from ISO-15693 NFC tag, whenever I start to read it I get this error
Error Domain=NFCError Code=102 "Tag response error" UserInfo={NSLocalizedDescription=Tag response error, ISO15693TagResponseErrorCode=2}
This is how I try to read it
tagHandler(NFCISO15693Tag.self, arguments, result) { tag in
let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String])
let blockNumber = arguments["blockNumber"] as! Int
let numberOfBlocks = arguments["numberOfBlocks"] as! Int
tag.readMultipleBlocks(requestFlags: requestFlags, blockRange: NSMakeRange(blockNumber, numberOfBlocks)) { dataBlocks, error in
if let error = error {
result(getFlutterError(error))
} else {
result(dataBlocks)
}
}
}
However I managed to read single block by changing request flags to [.highDataRate], but this change won't help on readMultipleblocks command
tagHandler(NFCISO15693Tag.self, arguments, result) { tag in
let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String])
let blockNumber = arguments["blockNumber"] as! UInt8
tag.readSingleBlock(requestFlags: [.highDataRate], blockNumber: blockNumber) { dataBlock, error in
if let error = error {
result(getFlutterError(error))
} else {
result(dataBlock)
}
}
}
I couldn't find many examples or resources about reading multiple blocks from ISO-15693 tag, so any information or an example would help! Thanks!
So I managed to find a workaround by using readSingle block with async threading. It takes about 0.6sec to read 50 blocks. I'm not familiar with swift language so I bet this could be optimised better.
@available(iOS 13.0, *)
private func handleIso15693ReadSingleBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) {
tagHandler(NFCISO15693Tag.self, arguments, result) { tag in
let accessQueue = DispatchQueue(label: "NFCManager.accessQueue")
let blockCount = arguments["blockNumber"] as! UInt8
var dataBlocks = [Data]()
let group = DispatchGroup()
group.enter();
for i in 3...blockCount{
accessQueue.async {
tag.readSingleBlock(requestFlags: [.highDataRate], blockNumber: UInt8(i)) { dataBlock, error in
if let error = error {
result(getFlutterError(error))
} else {
dataBlocks.append(dataBlock)
if (i == blockCount){
group.leave();
}
}
}
}
}
group.wait()
group.notify(queue: .main) {
result(dataBlocks)
}
}
}