Skip to content

Commit ec54bef

Browse files
committed
Enable write block for iOS MIFARE Classic
1 parent 46380e0 commit ec54bef

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ios/flutter_nfc_kit/Sources/flutter_nfc_kit/FlutterNfcKitPlugin.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,23 @@ public class FlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSessionDe
248248
tag.extendedWriteSingleBlock(requestFlags: RequestFlag(rawValue: rawFlags), blockNumber: blockNumber, dataBlock: data, completionHandler: handler)
249249
}
250250
} else {
251-
result(FlutterError(code: "405", message: "writeBlock not supported on this type of card", details: nil))
251+
if case let .miFare(tag) = tag {
252+
let blockNumber = arguments["index"] as! UInt8
253+
let writeCommand = Data([0xA2, blockNumber]) + data //0xA2 is the MIFARE Classic Write Command to write single block.
254+
tag.sendMiFareCommand(commandPacket: writeCommand) { (response, error) in
255+
if let error = error {
256+
result(FlutterError(code: "500", message: "Communication error", details: nil))
257+
}
258+
else
259+
{
260+
result(nil)
261+
}
262+
}
263+
}
264+
else
265+
{
266+
result(FlutterError(code: "405", message: "writeBlock not supported on this type of card", details: nil))
267+
}
252268
}
253269
} else if call.method == "readNDEF" {
254270
if tag != nil {

0 commit comments

Comments
 (0)