From 3f8021cdb32c222fda808d29a4f5d83a73d7ec33 Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 17 Apr 2024 12:42:48 +0200 Subject: [PATCH 1/2] fix(ios): fix sendMiFareCommand parameter and return value --- .../TiNfcMiFareUltralightTagTechnology.m | 34 +++++++++++++++---- ios/manifest | 2 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/ios/Classes/TiNfcMiFareUltralightTagTechnology.m b/ios/Classes/TiNfcMiFareUltralightTagTechnology.m index 4bff83e..72a0a59 100644 --- a/ios/Classes/TiNfcMiFareUltralightTagTechnology.m +++ b/ios/Classes/TiNfcMiFareUltralightTagTechnology.m @@ -30,29 +30,49 @@ - (TiBuffer *)historicalBytes return historicalBytes; } +NSString *getHexString(NSData *data) +{ + NSUInteger capacity = data.length * 2; + NSMutableString *sbuf = [NSMutableString stringWithCapacity:capacity]; + const unsigned char *buf = data.bytes; + NSInteger i; + for (i = 0; i < data.length; ++i) { + [sbuf appendFormat:@"%02lX", (unsigned long)buf[i]]; + } + return sbuf; +} + +NSData *arrayToData(NSArray *array) +{ + Byte bytes[[array count]]; + for (int i = 0; i < [array count]; i++) { + bytes[i] = [[array objectAtIndex:i] integerValue]; + } + NSData *payload = [[NSData alloc] initWithBytes:bytes length:[array count]]; + return payload; +} + - (void)sendMiFareCommand:(id)args { NSArray *commandData = [[args firstObject] valueForKey:@"data"]; - unsigned int dataValue[commandData.count]; - for (int i = 0; i < commandData.count; i++) { - dataValue[i] = [commandData[i] unsignedIntValue]; - } - NSData *data = [[NSData alloc] initWithBytes:dataValue length:commandData.count]; + NSData *data = arrayToData(commandData); [[self.tagProxy asNFCMiFareTag] sendMiFareCommand:data completionHandler:^(NSData *response, NSError *error) { if (![self _hasListeners:@"didSendMiFareCommand"]) { return; } + TiBuffer *responseData = [[TiBuffer alloc] _initWithPageContext:[self pageContext]]; NSMutableData *responsevalue = [NSMutableData dataWithData:response]; [responseData setData:responsevalue]; + [self fireEvent:@"didSendMiFareCommand" withObject:@{ @"errorCode" : error != nil ? NUMINTEGER([error code]) : [NSNull null], @"errorDescription" : error != nil ? [error localizedDescription] : [NSNull null], @"errorDomain" : error != nil ? [error domain] : [NSNull null], - @"responseDataLength" : responseData.length - + @"responseDataLength" : responseData.length, + @"hex" : getHexString(response) }]; }]; } diff --git a/ios/manifest b/ios/manifest index ec5f71b..eb73e86 100644 --- a/ios/manifest +++ b/ios/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 4.1.0 +version: 4.1.1 apiversion: 2 architectures: arm64 x86_64 description: ti.nfc From 8f5d99415373860e79a9ac443e8c4a197b26e67e Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 17 Apr 2024 12:44:07 +0200 Subject: [PATCH 2/2] fix example --- ios/example/NDEF/app.js | 2 +- ios/example/app.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/example/NDEF/app.js b/ios/example/NDEF/app.js index b0b8805..06b3660 100644 --- a/ios/example/NDEF/app.js +++ b/ios/example/NDEF/app.js @@ -82,7 +82,7 @@ var deviceWindow = Ti.UI.createWindow({ titleAttributes: { color: 'blue' } }); -var navDeviceWindow = Ti.UI.iOS.createNavigationWindow({ +var navDeviceWindow = Ti.UI.createNavigationWindow({ window: deviceWindow }); diff --git a/ios/example/app.js b/ios/example/app.js index 75b78ea..bd9985d 100644 --- a/ios/example/app.js +++ b/ios/example/app.js @@ -61,7 +61,7 @@ var deviceWindow = Ti.UI.createWindow({ title: 'Mifare Sample', titleAttributes: { color: 'blue' } }); -var navDeviceWindow = Ti.UI.iOS.createNavigationWindow({ +var navDeviceWindow = Ti.UI.createNavigationWindow({ window: deviceWindow }); @@ -81,7 +81,7 @@ nfcAdapter.addEventListener('didDetectTags', function (e) { Ti.API.info('didDetectTags with message' + (e.errorCode ? (' error code: ' + e.errorCode + ' error domain: ' + e.errorDomain + ' error description: ' + e.errorDescription) : ': Tag Detected')); logs.push('didDetectTags with message' + (e.errorCode ? (' error code: ' + e.errorCode + ' error domain: ' + e.errorDomain + ' error description: ' + e.errorDescription) : ': Tag Detected')); setData(logs); - + var mifare = nfcAdapter.createTagTechMifareUltralight({'tag':e.tags[0]}); mifare.addEventListener('didConnectTag', function (e) { Ti.API.info('didConnectTag with message' + (e.errorCode ? (' error code: ' + e.errorCode + ' error domain: ' + e.errorDomain + ' error description: ' + e.errorDescription) : ': MiFare Tag Connected'));