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

iOS text record defaulting to UTF-16 encoding #76

Open arrutherford opened 3 years ago

arrutherford commented 3 years ago

Hi there,

I've been using nfc_in_flutter on android quite successfully, but when I got around to setting it up on iOS the result wasn't as expected.

I am creating a tag with a single text record, on android it writes as expected (encoding the payload in utf8), however, on iOS it encodes as utf-16.

List records = [ NDEFRecord.text( payload, ) ];

Has anyone else seen this issue?

arrutherford commented 3 years ago

Ive managed to get it working by altering NfcInFlutterPlugin.m

altering the if statement at line 391 to the following: if ([@"T" isEqualToString:recordType]) { payloadData = [[NSString stringWithFormat:@"%c%@%@", recordLanguageCode.length, recordLanguageCode, recordPayload] dataUsingEncoding:NSUTF8StringEncoding]; tnfValue = NFCTypeNameFormatNFCWellKnown; }

it seems that the "wellKnownTypeTextPayloadWithString" function call in the original code always returned the record as utf16