hansemannn / iOS-NFC-Example

๐Ÿ“ฑ Example showing how to use the Core NFC API in iOS
511 stars 71 forks source link

Display of UID and TagType #16

Open erikm30 opened 6 years ago

erikm30 commented 6 years ago

Some apps, namely NFC Tools from wakdev and NFC NDEF READER https://itunes.apple.com/us/app/nfc-ndef-reader/id1286248064?mt=8 manage to show UID and TagType - see screenshots. Any idea how to access these properties ?

scottire commented 6 years ago

UUID is possible by using the array foundTags from the session in - (void) readerSession:(nonnull NFCNDEFReaderSession *)session didDetectNDEFs:(nonnull NSArray<NFCNDEFMessage *> *)messages

NSArray *foundTags = [session valueForKey:@"_foundTags"];
NSObject *tag = foundTags[0];
NSData *uuid = [tag valueForKey:@"_tagID"];

Accessing these is potentially insecure so best to have some verification in place with each valueForKey and accessed array. I don't know if it's possible without doing sketchy access to these instance variables yet.

screen shot 2017-09-22 at 09 17 19

I don't have enough tags to get all the Tag Types, but there is an enum type beside tagID and from the CoreNFC header files it says that NFC Forum Tag type 1 to 5 that is NDEF formatted are supported.

ttraub commented 6 years ago

[EDITED] Thank you! That works. The _tagID value agrees with TagInfo and OmniKey Reader (initially I posted it didn't work, sorry)

hansemannn commented 6 years ago

I'll add it to the visual example, thanks!

scottire commented 6 years ago

@hansemannn Here is how I did it for phonegap-nfc: https://github.com/chariotsolutions/phonegap-nfc/pull/287/files#diff-84fad93feff6a327c30a08cac8f546dfR171

hansemannn commented 6 years ago

The problem is that it looks like a private API and Apple will likely reject apps using that API. So besides the fact that the phonegap-PR might not get merged, I'm not sure if we should expose it as a best practice. Still wondering how the above apps got through review with that - probably obfuscated the call or Apple didn't catch it.

Swati2707 commented 6 years ago

Hello, I have been trying to read tag's UID with the sample app you provided. But its unable to read an empty tag's UID. My complete project is based on UID and I am unable to sort it out. https://drive.google.com/open?id=0B5RBua-pcqKwNzNUcVl5eXl0YXM

scottire commented 6 years ago

Apple will in fact reject an app that uses this private api. As for why you canโ€™t read a non-ndef formatted tag, itโ€™s because CoreNFC only detect tags that have properly formatted NDEF data.

Swati2707 commented 6 years ago

Thank you. Let me find a way to encode it in some other way.

Swati2707 commented 6 years ago

Hello, Well my client is getting his tag NDEF encoded with URL. I haven't received the tags yet. But I have to confirm if i will be able to read the UID of those tags. As I have noticed NXP app and want to know more about it. Can anyone help?

erikm30 commented 6 years ago

You can use the NDEF itself to transfer ("Mirror") the UID to the phone. (i.e. encode https://your.customer.com/some_path/uid/ resp. https://your.customer.com/some_path?uid=xx..xx). In case of NTAG 213 and other NXP tags, you can encode even "00..00" for all tags and let the mirror feature do the job of displaying the actual tag UID.

Seems that Apple is actively blocking features outside NDEF reading (see changelogs of some of the reader apps that had it before).,

Regards erikm

2017-11-02 6:45 GMT+01:00 Swati2707 notifications@github.com:

Hello, Well my client is getting his tag NDEF encoded with URL. I haven't received the tags yet. But I have to confirm if i will be able to read the UID of those tags. As I have noticed NXP app and want to know more about it. Can anyone help?

โ€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hansemannn/iOS11-NFC-Example/issues/16#issuecomment-341323693, or mute the thread https://github.com/notifications/unsubscribe-auth/AAxMcRp0lTZUJ_bjiAAGccgnT35P_NaCks5syVcGgaJpZM4PfDhe .

Swati2707 commented 6 years ago

Hey. Thank you so much erikm30.

kkscwcd commented 6 years ago

@erikm30 I am trying the same things but getting only payload and ID is always coming blank in my APP . When i used the NXP from Itunes store it read the ID . Can you please share the code for this which you mentioned above .

You can use the NDEF itself to transfer ("Mirror") the UID to the phone. (i.e. encode https://your.customer.com/some_path/uid/ resp. https://your.customer.com/some_path?uid=xx..xx). In case of NTAG 213 and other NXP tags, you can encode even "00..00" for all tags and let the mirror feature do the job of displaying the actual tag UID.

Please share some code for mirroring features so i can understand.

erikm30 commented 6 years ago

Also the next release of NXP TagInfo has to remove the ID from being displayed, just like the other apps. What I was referring to was a feature of the ICs - you can personalize them in such a way, that the NDEF contains the UID and make use of that.

2017-11-16 5:41 GMT+01:00 kkscwcd notifications@github.com:

@erikm30 https://github.com/erikm30 I am trying the same things but getting only payload and ID is always coming blank in my APP . When i used the NXP from Itunes store it read the ID . Can you please share the code for this which you mentioned above .

You can use the NDEF itself to transfer ("Mirror") the UID to the phone. (i.e. encode https://your.customer.com/some_path/uid/ resp. https://your.customer.com/some_path?uid=xx..xx). In case of NTAG 213 and other NXP tags, you can encode even "00..00" for all tags and let the mirror feature do the job of displaying the actual tag UID.

Please share some code for mirroring features so i can understand.

โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hansemannn/iOS11-NFC-Example/issues/16#issuecomment-344813993, or mute the thread https://github.com/notifications/unsubscribe-auth/AAxMcdiQv-RhasfrDPwj1-ZgnsXGQxZFks5s27z1gaJpZM4PfDhe .

cloudfirst commented 6 years ago

@erikm30 Why next release of NXP TagInfo App will remove the ID from being displayed ? for using the non-public API to read tagid ?

andyden9 commented 6 years ago

I tested, iOS 11.2 has been removed _tagID data and _UID is changing last 4 bytes every time you read NFC tag, and it's not UID at all (I guess it's encrypted). I didn't find any other private API that relates to uid.

zipnfc commented 6 years ago

We did have UID and types in our IOS NFC app but we have noticed since the latest build 11.2 on the iPhone these values are being suppressed. Hopefully one day they will just support it in the API. Our current version of PROX NFC Tag just shows unavailable so will remove on the next version until they appear again.

YZahringer commented 5 years ago

Any news with beta of iOS 12? https://developer.apple.com/documentation/corenfc?changes=latest_minor

zipnfc commented 5 years ago

Do you mean the availability of the UID? Have not checked as yet, but will do - there does not seem any information regarding it, but that is not always definitive.

Regards, Chris.

Chris Humphries CEO ZipNFC

T: +44(0)20 7193 6879 | M: +44(0)7900 300031

ZipNFC.Com http://zipnfc.com/ Linkedin http://uk.linkedin.com/in/chrishumphries Facebook http://www.facebook.com/zipnfc YouTube http://www.youtube.com/zipnfc Twitter http://www.twitter.com/zipnfc

On 6 Jun 2018, at 11:09, Yann Zahringer Ferrando notifications@github.com wrote:

Any news with beta of iOS 12? https://developer.apple.com/documentation/corenfc?changes=latest_minor https://developer.apple.com/documentation/corenfc?changes=latest_minor โ€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hansemannn/iOS11-NFC-Example/issues/16#issuecomment-395017772, or mute the thread https://github.com/notifications/unsubscribe-auth/AK9QyMKWhYtkR6ul9PUiQN_5axQIOdfwks5t56pvgaJpZM4PfDhe.

YZahringer commented 4 years ago

I haven't tried it yet, but I think we'll finally be able to read RFID cards correctly from iOS 13: https://developer.apple.com/documentation/corenfc?changes=latest_minor ๐Ÿพ ๐ŸŽ‰

ISO15693: https://developer.apple.com/documentation/corenfc/nfciso15693tag?changes=latest_minor MiFare: https://developer.apple.com/documentation/corenfc/nfcmifaretag?changes=latest_minor

zipnfc commented 4 years ago

Ah wow. Thank you so much for sharing. Had missed this! Looks like UID and writing will be available !!

Chris.

On 4 Jun 2019, at 08:01, Yann Zahringer Ferrando notifications@github.com wrote:

I haven't tried it yet, but I think we'll finally be able to read RFID cards correctly from iOS 13: https://developer.apple.com/documentation/corenfc?changes=latest_minor ๐Ÿพ ๐ŸŽ‰

ISO15693: https://developer.apple.com/documentation/corenfc/nfciso15693tag?changes=latest_minor MiFare: https://developer.apple.com/documentation/corenfc/nfcmifaretag?changes=latest_minor

โ€” You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

scottire commented 4 years ago

As for why you canโ€™t read a non-ndef formatted tag, itโ€™s because CoreNFC only detect tags that have properly formatted NDEF data.

This is no longer true with iOS 13! The ability to send APDUs to MIFARE and FeliCa tags (or any tags that conform to ISO 15693 or ISO 7816) means you can manually read data from these tags. Another exciting update is the ability to read Value Added Service (VAS) tags.

Looks like UID and writing will be available

There's an identifier field on some of the tag types which is very likely (need to test to be sure) the UID (see here). As for writing, see this new official tutorial for an example of writing a tag with NDEF formatted data.

YZahringer commented 4 years ago

WWDC 19 Core NFC Enhancements session: https://developer.apple.com/videos/play/wwdc2019/715/

lyl155 commented 4 years ago

How do I read the tag's uid

Dev- commented 4 years ago

Does anyone know how to actually achive this in iOS 13?

I see lots of posts and statements from Apple and other commentators thats it's possible but I've not seen any implementation in code.

https://stackoverflow.com/questions/57978507/reading-uids-of-nfc-cards-in-ios-13

scottire commented 4 years ago

How do I read the tag's uid

Assuming the tag is a not a NFCFeliCaTag, it is available in the identifier property of the tag object.

func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {      
  if case let NFCTag.miFare(tag) = tags.first! {
    print(tag.identifier as NSData)
  }
}
krevelen commented 4 years ago

@erikm30 @hansemannn @scottire did any of you happen to try reading the UID from a MIFARE Classic (emulation) tag with iOS13 yet? I was able to confirm the new support for the DESfire and UltraLight ICs in the MIFARE Family, but for various MIFARE Classic ICs (the unknown family member?) my Console shows different error types. Would private APIs perhaps be helpful here, e.g. to intercept and amend the discovery polling routine?

  1. an Infineon Classic 4k Emulation actually logs 1 tags found with the correct UID (31:9A:2F:88), ATQA (0x0200), SAK (0x20 and 0x18, both included in the actual value: 0x38) and tag type (both Generic 4A and MiFare detected), but then throws a Stack Error:

    error 14:48:08.675369 +0200 nfcd 00000001 04e04390 - [NFDriverWrapper connectTag:]:1436 Failed to connect to tag: <NFTagInternal: 0x104e05cd0>-{length = 8, bytes = 0x7bad030077180efa} { Tech=A Type=Generic 4A ID={length = 4, bytes = 0x319a2f88} SAK={length = 1, bytes = 0x20} ATQA={length = 2, bytes = 0x0200} historicalBytes={length = 0, bytes = 0x}} : error 14:48:08.682881 +0200 nfcd 00000001 04e04390 - [NFDriverWrapper connectTag:]:1436 Failed to connect to tag: <NFTagInternal: 0x104e1d600>-{length = 8, bytes = 0x81ad0300984374f3} { Tech=A Type=MiFare ID={length = 4, bytes = 0x319a2f88} SAK={length = 1, bytes = 0x18} ATQA={length = 2, bytes = 0x0200} historicalBytes={length = 0, bytes = 0x}} : default 14:48:08.683150 +0200 nfcd 00000001 04e07470 - [_NFReaderSession handleRemoteTagsDetected:]:445 1 tags found default 14:48:08.685792 +0200 nfcd 00000001 04e07470 - [_NFReaderSession connect:callback:]:507 NFC-Example : error 14:48:08.693429 +0200 nfcd 00000001 04e04390 - [NFDriverWrapper connectTag:]:1436 Failed to connect to tag: <NFTagInternal: 0x104e05cd0>-{length = 8, bytes = 0x81ad0300984374f3} { Tech=A Type=MiFare ID={length = 4, bytes = 0x319a2f88} SAK=(null) ATQA=(null) historicalBytes={length = 0, bytes = 0x}} : error 14:48:08.694019 +0200 NFC-Example 00000002 802e2700 - [NFCTagReaderSession _connectTag:error:]:568 Error Domain=NFCError Code=100 "Stack Error" UserInfo={NSLocalizedDescription=Stack Error, NSUnderlyingError=0x2822a86c0 {Error Domain=nfcd Code=15 "Stack Error" UserInfo={NSLocalizedDescription=Stack Error}}}

  2. an NXP SmartMX (Classic 4k emulation) with UID CF:3E:40:04 is discovered initially, but a reception error during ISO 14443-4A presence check (Proc Iso-Dep pres chk ntf: Receiption failed) continuously restarts the discovery polling until the session finally expires:

    error 10:44:50.650673 +0200 nfcd Proc Iso-Dep pres chk ntf: Receiption failed : error 10:44:50.677470 +0200 nfcd 00000001 04e04390 - [NFDriverWrapper disconnectTag:tagRemovalDetect:]:1448 Failed to disconnect tag: <NFTagInternal: 0x104f09930>-{length = 8, bytes = 0x07320d00f3041861} { Tech=A Type=Generic 4A ID={length = 4, bytes = 0xcf3e4004} SAK={length = 1, bytes = 0x20} ATQA={length = 2, bytes = 0x0200} historicalBytes={length = 0, bytes = 0x}} default 10:44:50.677682 +0200 nfcd 00000001 04e04390 -

  3. an actual NXP Classic 4k with UID 2D:FE:9B:87 remains undetected and throws no error. This one simply times out after 60 seconds and logs the last 128 discovery messages transmitted (Tx) and received (Rx), among which the following pattern is repeated (I'm assuming REQA and ATQA messages?):

    error 11:42:19.511354 +0200 nfcd 1571305339.350902 Tx '21 03 07 03 FF 01 00 01 01 01 6F 61' error 11:42:19.511484 +0200 nfcd 1571305339.353416 Rx '41 03 01' error 11:42:19.511631 +0200 nfcd 1571305339.353486 Rx '00 F6 89' error 11:42:19.511755 +0200 nfcd 1571305339.362455 Rx '61 05 14' error 11:42:19.511905 +0200 nfcd 1571305339.362529 Rx '01 80 80 00 FF 01 09 02 00 04 2D FE 9B 87 01 18 00 00 00 00 2D 11'

    error 11:42:19.512152 +0200 nfcd 1571305339.362734 Tx '21 06 01 00 44 AB' error 11:42:19.512323 +0200 nfcd 1571305339.363959 Rx '41 06 01' error 11:42:19.512489 +0200 nfcd 1571305339.364028 Rx '00 1D 79' error 11:42:19.512726 +0200 nfcd 1571305339.364300 Rx '61 06 02' error 11:42:19.512914 +0200 nfcd 1571305339.364347 Rx '00 00 EB 78'

vinksharma commented 3 years ago

As per my findings ->
UID is still accessible if you're using 'NFCTagReaderSession' and inaccessible using 'NFCNdefReaderSession' .

Few tags can't be read/detected using 'NFCTagReaderSession', but the TAGs which are readable using NFCTagReaderSession should be able to read and detect UID class NFCTagReaderSession --- A reader session for detecting ISO7816, ISO15693, FeliCa, and MIFARE tags.

Reader Reference