Skip to content

Commit 8fdee8b

Browse files
fix(ios): fixed all data commands as data in tibuffer was not valid
1 parent 1935d31 commit 8fdee8b

File tree

1 file changed

+66
-21
lines changed

1 file changed

+66
-21
lines changed

ios/Classes/TiNfcVTagTechnology.m

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ - (void)writeSingleBlockWithRequestFlags:(id)args
6868
NSNumber *blockNumberValue = [[args firstObject] valueForKey:@"blockNumber"];
6969
uint8_t blockNumber = [blockNumberValue unsignedCharValue];
7070

71-
TiBuffer *dataBlock = [[args firstObject] valueForKey:@"blockNumber"];
71+
NSArray *dataBlock = [[args firstObject] valueForKey:@"blockNumber"];
72+
unsigned int dataValue[dataBlock.count];
73+
for (int i = 0; i < dataBlock.count; i++) {
74+
dataValue[i] = [dataBlock[i] unsignedIntValue];
75+
}
76+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:dataBlock.count];
7277

7378
[[self.tagProxy asNFCISO15693Tag] writeSingleBlockWithRequestFlags:requestFlags
7479
blockNumber:blockNumber
75-
dataBlock:dataBlock.data
80+
dataBlock:data
7681
completionHandler:^(NSError *_Nullable error) {
7782
if (![self _hasListeners:@"didWriteSingleBlockWithRequestFlags"]) {
7883
return;
@@ -143,12 +148,18 @@ - (void)writeMultipleBlocksWithRequestFlags:(id)args
143148
NSNumber *requestFlagsValue = [[args firstObject] valueForKey:@"requestFlags"];
144149
uint8_t requestFlags = [requestFlagsValue unsignedCharValue];
145150

146-
TiBuffer *responseDataValue = [[args firstObject] valueForKey:@"blockNumber"];
147-
NSArray *dataBlock = [[NSArray alloc] initWithObjects:responseDataValue, nil];
151+
NSArray *dataBlock = [[args firstObject] valueForKey:@"blockNumber"];
152+
unsigned int dataValue[dataBlock.count];
153+
for (int i = 0; i < dataBlock.count; i++) {
154+
dataValue[i] = [dataBlock[i] unsignedIntValue];
155+
}
156+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:dataBlock.count];
157+
158+
NSArray *dataBlocks = [[NSArray alloc] initWithObjects:data, nil];
148159

149160
[[self.tagProxy asNFCISO15693Tag] writeMultipleBlocksWithRequestFlags:requestFlags
150161
blockRange:NSMakeRange(0, 8)
151-
dataBlocks:dataBlock
162+
dataBlocks:dataBlocks
152163
completionHandler:^(NSError *_Nullable error) {
153164
if (![self _hasListeners:@"didWriteMultipleBlocksWithRequestFlags"]) {
154165
return;
@@ -305,11 +316,16 @@ - (void)customCommandWithRequestFlag:(id)args
305316

306317
NSNumber *customCommandCode = [[args firstObject] valueForKey:@"customCommandCode"];
307318

308-
TiBuffer *customRequestParameters = [[args firstObject] valueForKey:@"customRequestParameters"];
319+
NSArray *customRequestParameters = [[args firstObject] valueForKey:@"customRequestParameters"];
320+
unsigned int dataValue[customRequestParameters.count];
321+
for (int i = 0; i < customRequestParameters.count; i++) {
322+
dataValue[i] = [customRequestParameters[i] unsignedIntValue];
323+
}
324+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:customRequestParameters.count];
309325

310326
[[self.tagProxy asNFCISO15693Tag] customCommandWithRequestFlag:requestFlags
311327
customCommandCode:[customCommandCode integerValue]
312-
customRequestParameters:customRequestParameters.data
328+
customRequestParameters:data
313329
completionHandler:^(NSData *_Nonnull customResponseParameters, NSError *_Nullable error) {
314330
if (![self _hasListeners:@"didCustomCommandWithRequestFlag"]) {
315331
return;
@@ -360,11 +376,16 @@ - (void)extendedWriteSingleBlockWithRequestFlags:(id)args
360376

361377
NSNumber *blockNumber = [[args firstObject] valueForKey:@"blockNumber"];
362378

363-
TiBuffer *dataBlock = [[args firstObject] valueForKey:@"dataBlock"];
379+
NSArray *dataBlock = [[args firstObject] valueForKey:@"dataBlock"];
380+
unsigned int dataValue[dataBlock.count];
381+
for (int i = 0; i < dataBlock.count; i++) {
382+
dataValue[i] = [dataBlock[i] unsignedIntValue];
383+
}
384+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:dataBlock.count];
364385

365386
[[self.tagProxy asNFCISO15693Tag] extendedWriteSingleBlockWithRequestFlags:requestFlags
366387
blockNumber:[blockNumber integerValue]
367-
dataBlock:dataBlock.data
388+
dataBlock:data
368389
completionHandler:^(NSError *_Nullable error) {
369390
if (![self _hasListeners:@"didExtendedReadSingleBlockWithRequestFlags"]) {
370391
return;
@@ -448,11 +469,16 @@ - (void)authenticateWithRequestFlags:(id)args
448469

449470
NSNumber *cryptoSuiteIdentifier = [[args firstObject] valueForKey:@"cryptoSuiteIdentifier"];
450471

451-
TiBuffer *message = [[args firstObject] valueForKey:@"message"];
472+
NSArray *message = [[args firstObject] valueForKey:@"message"];
473+
unsigned int dataValue[message.count];
474+
for (int i = 0; i < message.count; i++) {
475+
dataValue[i] = [message[i] unsignedIntValue];
476+
}
477+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:message.count];
452478

453479
[[self.tagProxy asNFCISO15693Tag] authenticateWithRequestFlags:requestFlags
454480
cryptoSuiteIdentifier:[cryptoSuiteIdentifier integerValue]
455-
message:message.data
481+
message:data
456482
completionHandler:^(NFCISO15693ResponseFlag responseFlag, NSData *_Nonnull response, NSError *_Nullable error) {
457483
if (![self _hasListeners:@"didAuthenticateWithRequestFlags"]) {
458484
return;
@@ -473,11 +499,16 @@ - (void)challengeWithRequestFlags:(id)args
473499

474500
NSNumber *cryptoSuiteIdentifier = [[args firstObject] valueForKey:@"cryptoSuiteIdentifier"];
475501

476-
TiBuffer *message = [[args firstObject] valueForKey:@"message"];
502+
NSArray *message = [[args firstObject] valueForKey:@"message"];
503+
unsigned int dataValue[message.count];
504+
for (int i = 0; i < message.count; i++) {
505+
dataValue[i] = [message[i] unsignedIntValue];
506+
}
507+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:message.count];
477508

478509
[[self.tagProxy asNFCISO15693Tag] challengeWithRequestFlags:requestFlags
479510
cryptoSuiteIdentifier:[cryptoSuiteIdentifier integerValue]
480-
message:message.data
511+
message:data
481512
completionHandler:^(NSError *_Nullable error) {
482513
if (![self _hasListeners:@"didChallengeWithRequestFlags"]) {
483514
return;
@@ -536,12 +567,17 @@ - (void)extendedWriteMultipleBlocksWithRequestFlags:(id)args
536567
NSNumber *requestFlagsValue = [[args firstObject] valueForKey:@"requestFlags"];
537568
uint8_t requestFlags = [requestFlagsValue unsignedCharValue];
538569

539-
TiBuffer *responseDataValue = [[args firstObject] valueForKey:@"dataBlock"];
540-
NSArray *dataBlock = [[NSArray alloc] initWithObjects:responseDataValue, nil];
570+
NSArray *dataBlock = [[args firstObject] valueForKey:@"dataBlock"];
571+
unsigned int dataValue[dataBlock.count];
572+
for (int i = 0; i < dataBlock.count; i++) {
573+
dataValue[i] = [dataBlock[i] unsignedIntValue];
574+
}
575+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:dataBlock.count];
576+
NSArray *dataBlocks = [[NSArray alloc] initWithObjects:data, nil];
541577

542578
[[self.tagProxy asNFCISO15693Tag] extendedWriteMultipleBlocksWithRequestFlags:requestFlags
543579
blockRange:NSMakeRange(0, 8)
544-
dataBlocks:dataBlock
580+
dataBlocks:dataBlocks
545581
completionHandler:^(NSError *_Nullable error) {
546582
if (![self _hasListeners:@"didExtendedWriteMultipleBlocksWithRequestFlags"]) {
547583
return;
@@ -601,11 +637,16 @@ - (void)keyUpdateWithRequestFlags:(id)args
601637

602638
NSNumber *keyIdentifier = [[args firstObject] valueForKey:@"keyIdentifier"];
603639

604-
TiBuffer *message = [[args firstObject] valueForKey:@"message"];
640+
NSArray *message = [[args firstObject] valueForKey:@"message"];
641+
unsigned int dataValue[message.count];
642+
for (int i = 0; i < message.count; i++) {
643+
dataValue[i] = [message[i] unsignedIntValue];
644+
}
645+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:message.count];
605646

606647
[[self.tagProxy asNFCISO15693Tag] keyUpdateWithRequestFlags:requestFlags
607648
keyIdentifier:[keyIdentifier integerValue]
608-
message:message.data
649+
message:data
609650
completionHandler:^(NFCISO15693ResponseFlag responseFlag, NSData *_Nonnull response, NSError *_Nullable error) {
610651
if (![self _hasListeners:@"didKeyUpdateWithRequestFlags"]) {
611652
return;
@@ -643,11 +684,15 @@ - (void)sendRequestWithFlag:(id)args
643684
NSNumber *flag = [[args firstObject] valueForKey:@"flag"];
644685
NSNumber *commandCode = [[args firstObject] valueForKey:@"commandCode"];
645686

646-
TiBuffer *data = [[args firstObject] valueForKey:@"data"];
647-
687+
NSArray *commandData = [[args firstObject] valueForKey:@"data"];
688+
unsigned int dataValue[commandData.count];
689+
for (int i = 0; i < commandData.count; i++) {
690+
dataValue[i] = [commandData[i] unsignedIntValue];
691+
}
692+
NSData *data = [[NSData alloc] initWithBytes:dataValue length:commandData.count];
648693
[[self.tagProxy asNFCISO15693Tag] sendRequestWithFlag:[flag integerValue]
649694
commandCode:[commandCode integerValue]
650-
data:data.data
695+
data:data
651696
completionHandler:^(NFCISO15693ResponseFlag responseFlag, NSData *_Nullable data, NSError *_Nullable error) {
652697
if (![self _hasListeners:@"didReadBufferWithRequestFlags"]) {
653698
return;

0 commit comments

Comments
 (0)