Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): fix sendMiFareCommand parameter and return value #84

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions ios/Classes/TiNfcMiFareUltralightTagTechnology.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}];
}];
}
Expand Down
2 changes: 1 addition & 1 deletion ios/example/NDEF/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down
4 changes: 2 additions & 2 deletions ios/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand All @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading