semlette / nfc_in_flutter

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.
MIT License
120 stars 119 forks source link

NDEFRecord.text causes NSInternalInconsistencyException when writing on iOS #17

Closed janipiippow closed 4 years ago

janipiippow commented 4 years ago

For some reason using NDEFRecord.text or NDEFRecord.custom with type "T" and TNF Well Known when writing on a tag on iOS causes an exception listed below:

2019-10-22 09:57:47.847897+0300 Runner[269:5769] *** Assertion failure in +[NFCNDEFPayload wellKnowTypeTextPayloadWithString:locale:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreNFC/Stockholm-300.59.2/CoreNFC/NFCNDEFPayload.m:188
2019-10-22 09:57:47.848353+0300 Runner[269:5769] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Please use -wellKnownTypeTextPayloadWithString:locale: replacement'
*** First throw call stack:
(0x180f4c98c 0x180c750a4 0x180e4ed1c 0x1812848f4 0x1a964cbd0 0x102599ca8 0x10259b0a4 0x102597b6c 0x1025976f4 0x104489828 0x10448ac04 0x104491b74 0x104492710 0x10449dae4 0x180c69fa4 0x180c6cae0)
libc++abi.dylib: terminating with uncaught exception of type NSException

Other TNF's do not seem to cause this with same payload. However, my tags work only with Well Known type T write messages (tested with Android) so I would appreciate, if someone have more insight on how to fix this.

semlette commented 4 years ago

I am about to take a closer look. I think the error occurs between line 391 and 395 in NfcInFlutterPlugin.m.

janipiippow commented 4 years ago

You are most likely right. After searching, I think that wellKnowTypeTextPayloadWithString should probably be changed to wellKnownTypeTextPayloadWithString on row 393. wellKnowTypeTextPayloadWithString is marked depracated and that is probably the exception is thrown.

semlette commented 4 years ago

Good spot!

Replacing it with wellKnownTypeTextPayloadWithString seems to do the trick.

- wellKnowTypeTextPayloadWithString
+ wellKnownTypeTextPayloadWithString

The only difference is a 'n'. I wonder if it was a typo 🤔

I'll release a new version with the fix shortly.

semlette commented 4 years ago

I have released version v2.0.1 with the fix.

janipiippow commented 4 years ago

Nice, thank you!