@@ -210,7 +210,19 @@ public class FlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSessionDe
210210 let blockNumber = arguments [ " index " ] as! Int
211211 tag. extendedReadSingleBlock ( requestFlags: RequestFlag ( rawValue: rawFlags) , blockNumber: blockNumber, completionHandler: handler)
212212 }
213- } else {
213+ }
214+ else if case let . miFare( tag) = tag {
215+ let blockNumber = arguments [ " index " ] as! UInt8
216+ let commandPacket = Data ( [ 0x30 , blockNumber] ) //0x30 is the MIFARE Classic Read Command.
217+ tag. sendMiFareCommand ( commandPacket: commandPacket) { ( data, error) in
218+ if let error = error {
219+ result ( FlutterError ( code: " 405 " , message: " Something is wrong " , details: nil ) )
220+ } else {
221+ result ( data)
222+ }
223+ }
224+ }
225+ else {
214226 result ( FlutterError ( code: " 405 " , message: " readBlock not supported on this type of card " , details: nil ) )
215227 }
216228 } else if call. method == " writeBlock " {
@@ -233,8 +245,22 @@ public class FlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSessionDe
233245 let blockNumber = arguments [ " index " ] as! Int
234246 tag. extendedWriteSingleBlock ( requestFlags: RequestFlag ( rawValue: rawFlags) , blockNumber: blockNumber, dataBlock: data, completionHandler: handler)
235247 }
236- } else {
237- result ( FlutterError ( code: " 405 " , message: " writeBlock not supported on this type of card " , details: nil ) )
248+ }
249+ else if case let . miFare( tag) = tag {
250+ let blockNumber = arguments [ " index " ] as! UInt8
251+ let writeCommand = Data ( [ 0xA2 , blockNumber] ) + data //0xA2 is the MIFARE Classic Write Command to write single block.
252+ tag. sendMiFareCommand ( commandPacket: writeCommand) { ( response, error) in
253+ if let error = error {
254+ result ( FlutterError ( code: " 500 " , message: " Communication error " , details: nil ) )
255+ }
256+ else
257+ {
258+ result ( nil )
259+ }
260+ }
261+ }
262+ else {
263+ result ( FlutterError ( code: " 405 " , message: " writeBlock not supported on this type of card " , details: nil ) )
238264 }
239265 } else if call. method == " readNDEF " {
240266 if tag != nil {
0 commit comments