capawesome-team / capacitor-nfc

⚡️ Capacitor plugin for reading and writing NFC tags.
https://capawesome.io/plugins/nfc/
MIT License
73 stars 14 forks source link

bug: receiving "The NFC tag does not support the selected techType." while using transceive #43

Closed marchein closed 11 months ago

marchein commented 11 months ago

Plugin version:

"@capawesome-team/capacitor-nfc": "^5.0.2"

Platform(s):

"@capacitor/ios": "^5.6.0",

Current behavior:

Using a NTAG 213 card I read the card, after that I initialize a transceive session I receive an error: "The NFC tag does not support the selected techType."

Expected behavior:

The plugin tells me at least what tech type the card had, but given the output of the nfcTag obj property techTypes states NDEF, it should let me proceed...

Steps to reproduce:

  1. Execute the example
  2. Press scan card
  3. Scan card using a real device
  4. The issue appears

Related code:

See minimal, reproducible example: https://github.com/marchein/capacitor-nfc-techtype-issue

Other information:

Log output from Xcode

⚡️  To Native ->  Nfc addListener 122730965
⚡️  To Native ->  Nfc startScanSession 122730966
⚡️  TO JS undefined

⚡️  TO JS {"nfcTag":{"isWritable":false,"id":[4,156,84,178,62,80,128],"techTypes":["NDEF","MIFARE_DESFIRE"],"historicalBytes":[128],"maxSize":0}}
⚡️  To Native ->  Nfc stopScanSession 122730967
⚡️  TO JS undefined
⚡️  [log] - --------------- Output Card Info ---------------
⚡️  [log] - {"isWritable":false,"id":[4,156,84,178,62,80,128],"techTypes":["NDEF","MIFARE_DESFIRE"],"historicalBytes":[128],"maxSize":0}
⚡️  [log] - ATQA: undefined
⚡️  [log] - Application Data: undefined
⚡️  [log] - Barcode: undefined
⚡️  [log] - Can Make Read-Only: undefined
⚡️  [log] - DSF ID: undefined
⚡️  [log] - Hi Layer Response: undefined
⚡️  [log] - Historical Bytes: [128]
⚡️  [log] - ID: [4,156,84,178,62,80,128]
⚡️  [log] - Is Writable: false
⚡️  [log] - Manufacturer: undefined
⚡️  [log] - Max Size: 0
⚡️  [log] - Message: undefined
⚡️  [log] - Protocol Info: undefined
⚡️  [log] - Response Flags: undefined
⚡️  [log] - SAK: undefined
⚡️  [log] - System Code: undefined
⚡️  [log] - Tech Types: ["NDEF","MIFARE_DESFIRE"]
⚡️  [log] - Type: undefined
⚡️  [log] - --------------- Output Card Info END ---------------
⚡️  [log] - --------------- Card Identifier ---------------
⚡️  [log] - ID: 36117027229047812
⚡️  [log] - Hex ID: 049c54b23e5080
⚡️  [log] - --------------- Card Identifier END ---------------
⚡️  [log] - --------------- Send Command Select App --------------- 
⚡️  [log] - App ID: [95,132,21]
⚡️  [log] - App ID Bytes: [95,132,21]
⚡️  [log] - Select App Command: {"0":144,"1":90,"2":0,"3":0,"4":3,"5":95,"6":132,"7":21,"8":0}
⚡️  [log] - Select App Command Hex: 905a0000035f841500
⚡️  [log] - -------------------- Send NFC Request --------------------
⚡️  [log] - Tag: {"isWritable":false,"id":[4,156,84,178,62,80,128],"techTypes":["NDEF","MIFARE_DESFIRE"],"historicalBytes":[128],"maxSize":0}
⚡️  [log] - techType: NDEF
⚡️  [log] - Request: {"0":144,"1":90,"2":0,"3":0,"4":3,"5":95,"6":132,"7":21,"8":0}
⚡️  [log] - Request Hex: 905a0000035f841500
⚡️  [log] - Request Int: 2.6628163300920766e+21
⚡️  [log] - Request Bytes: [144,90,0,0,3,95,132,21,0]
⚡️  To Native ->  Nfc transceive 122730968
ERROR MESSAGE:  {"message":"The NFC tag does not support the selected techType.","errorMessage":"The NFC tag does not support the selected techType."}
⚡️  [error] - {"message":"The NFC tag does not support the selected techType.","errorMessage":"The NFC tag does not support the selected techType."}
⚡️  [log] - {"errorMessage":"The NFC tag does not support the selected techType."}
⚡️  [log] - Response: {}
⚡️  [log] - Response Hex: 
⚡️  [log] - Response Int: NaN

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 5.6.0
  @capacitor/core: 5.6.0
  @capacitor/android: 5.6.0
  @capacitor/ios: 5.6.0

Installed Dependencies:

  @capacitor/android: not installed
  @capacitor/cli: 5.6.0
  @capacitor/ios: 5.6.0
  @capacitor/core: 5.6.0

[success] iOS looking great! 👌
robingenz commented 11 months ago

Thank you for your request.

According to our documentation, we currently only support the tag tech types NfcF and NfcV on iOS. Ndef generally does not support custom commands. But I was able to add support for the tech type MifareDesfire, which your NFC tag seems to support as well.

⚡️ [log] - {"isWritable":false,"id":[4,156,84,178,62,80,128],"techTypes":["NDEF","MIFARE_DESFIRE"],"historicalBytes":[128],"maxSize":0}

Here you can find a dev version for testing:

npm i @capawesome-team/capacitor-nfc@5.0.2-dev.61fde2a.1703067017

Let me know if it helps you.

marchein commented 11 months ago

Thank you for your quick response.

I was able to let the card scan. But now I receive a new error: Tag is not connected

⚡️  [log] - --------------- Send Command Select App --------------- 
⚡️  [log] - App ID: [95,132,21]
⚡️  [log] - App ID Bytes: [95,132,21]
⚡️  [log] - Select App Command: {"0":144,"1":90,"2":0,"3":0,"4":3,"5":95,"6":132,"7":21,"8":0}
⚡️  [log] - Select App Command Hex: 905a0000035f841500
⚡️  [log] - -------------------- Send NFC Request --------------------
⚡️  [log] - Tag: {"techTypes":["NDEF","MIFARE_DESFIRE"],"historicalBytes":[128],"maxSize":0,"id":[4,156,84,178,62,80,128],"isWritable":false}
⚡️  [log] - techType: MIFARE_DESFIRE
⚡️  [log] - Request: {"0":144,"1":90,"2":0,"3":0,"4":3,"5":95,"6":132,"7":21,"8":0}
⚡️  [log] - Request Hex: 905a0000035f841500
⚡️  [log] - Request Int: 2.6628163300920766e+21
⚡️  [log] - Request Bytes: [144,90,0,0,3,95,132,21,0]
⚡️  To Native ->  Nfc transceive 80945129
ERROR MESSAGE:  {"errorMessage":"Tag is not connected","message":"Tag is not connected"}
⚡️  [error] - {"errorMessage":"Tag is not connected","message":"Tag is not connected"}
⚡️  [log] - {"errorMessage":"Tag is not connected"}
⚡️  [log] - Response: {}
⚡️  [log] - Response Hex: 
⚡️  [log] - Response Int: NaN

This could be related to https://github.com/capawesome-team/capacitor-plugins/issues/125 I guess.

Commited the changes to my repository as well, so you could check please, if you got any ideas how to fix it...

Thank you!

robingenz commented 11 months ago

Thank you for the update. I am closing this issue because the original problem has been solved. I will work on capawesome-team/capacitor-plugins#125 next.

robingenz commented 11 months ago

I just noticed that capawesome-team/capacitor-plugins#125 only affects Android, not iOS. I tested your example locally and was able to reproduce the problem. I noticed that the error is not thrown by the plugin itself but by this method from Core NFC.

According to this SO thread, the reason for this error message was that an invalid command was sent. So please make sure that you send a valid command to the NFC tag. Unfortunately, I'm not familiar enough with the custom commands for MIFARE DESFire to give you a tip.

EDIT: If you have any further questions, please create a new discussion/issue so that we can deal with the two problems separately.