skip to Main Content

I’m trying to write to a Mifare Ultralight NFC but I get this error:

Optional(Error Domain=NFCError Code=1 "Feature not supported" UserInfo={NSLocalizedDescription=Feature not supported})

I’m using this code for write:

if case let NFCTag.miFare(tag) = tags.first! {
            let dataMifare: [UInt8] = [240, 0, 0, 0] // READ page 4 + CRC
            let dataPacketMifare = Data(bytes: dataMifare, count: dataMifare.count)
            session.connect(to: tags.first!) { (error: Error?) in
let apdu = NFCISO7816APDU(instructionClass: 0xFF, instructionCode: 0xD6, p1Parameter: 0x00, p2Parameter: 0xFF, data: dataPacketMifare, expectedResponseLength: 0x02)
               
                
tag.sendMiFareISO7816Command(apdu) { (apduData, sw1, sw2, error) in
    let tagUIDData = tag.identifier
    session.invalidate(errorMessage: "Test")
    debugPrint(apduData)
    debugPrint(error)
    debugPrint(tag.identifier)

My Info.plist file:

<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
    <array>
    <string>D2760000850100</string>
    <string>D2760000850101</string>
    </array>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
    <string>NDEF</string>
    <string>TAG</string>
</array>

I’m writing to a custom device where the value "0xFF" means a write request.
If I change that value with "0x00" it works but for my device that is a read request

Am I doing something wrong or IOS 13.0 does not really support writing request on the Mifare?

I’m using Xcode 12.2, iOS 13.0 and Iphone 11.

Thanks in advance for the help

UPDATE 1 for Andrew reply

This is my code:

func handlerResponse(Result: Result< Data, Error>){
    print("error")
}

let dataMifareTest: [UInt8] = [0xF0, 0, 0, 0] 
let dataPacketMifareTest = Data(bytes: dataMifareTest, count: dataMifareTest.count)
tag.sendMiFareCommand(commandPacket: dataPacketMifareTest, resultHandler: handlerResponse)

But I get the following error:

NFCTagReader[516:101552] [CoreNFC] 00000002 83fd0090 -[NFCTagReaderSession transceive:tagUpdate:error:]:771  Error Domain=NFCError Code=100 "Tag connection lost" UserInfo={NSLocalizedDescription=Tag connection lost}

2

Answers


  1. Yes you are doing something wrong, A Mifare Ultralight is not a ISO7816 capable card.

    If you look at
    https://developer.apple.com/documentation/corenfc/nfcmifaretag/3153114-sendmifareiso7816command

    It says

    Use this method to send commands to tags that have a mifareFamily
    value of either NFCMiFareFamily.plus or NFCMiFareFamily.desfire.

    You cannot send a Mifare Ultralight APDU’s, some of the Mifare cards like the desfire are multi standard cards.

    Update:

    Tag connection lost quite often mean that the card has a error and it goes in to the HALT state and no further comms can be made to the card until it is reset by usually going in and out of the RF field.

    In your original question you say

    I’m writing to a custom device where the value "0xFF" means a write request.

    But you seem to be sending it 0xF0 instead which is different and might not be a valid command to it.

    Login or Signup to reply.
  2. the problem is that you send has not the payload datas.
    The array [0xF0, 0, 0, 0] has only the page request.
    The error:

    NFCTagReader[516:101552] [CoreNFC] 00000002 83fd0090 -[NFCTagReaderSession transceive:tagUpdate:error:]:771  Error Domain=NFCError Code=100 "Tag connection lost" UserInfo={NSLocalizedDescription=Tag connection lost}
    

    is a malformed request.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search