react-native-nfc-manager 3.12.0 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -48,6 +48,17 @@ declare module 'react-native-nfc-manager' {
48
48
  Select = 1 << 4,
49
49
  Address = 1 << 5,
50
50
  Option = 1 << 6,
51
+ CommandSpecificBit8 = 1 << 7,
52
+ }
53
+
54
+ export enum Nfc15693ResponseFlagIOS {
55
+ Error = 1 << 0,
56
+ ResponseBufferValid = 1 << 1,
57
+ FinalResponse = 1 << 2,
58
+ ProtocolExtension = 1 << 3,
59
+ BlockSecurityStatusBit5 = 1 << 4,
60
+ BlockSecurityStatusBit6 = 1 << 5,
61
+ WaitTimeExtension = 1 << 6,
51
62
  }
52
63
 
53
64
  type TNF = 0x0 | 0x01 | 0x02 | 0x03 | 0x04 | 0x05 | 0x06 | 0x07;
@@ -94,6 +105,10 @@ declare module 'react-native-nfc-manager' {
94
105
  transceive: (bytes: number[]) => Promise<number[]>;
95
106
  }
96
107
 
108
+ interface NfcVHandler {
109
+ transceive: (bytes: number[]) => Promise<number[]>;
110
+ }
111
+
97
112
  interface IsoDepHandler {
98
113
  transceive: (bytes: number[]) => Promise<number[]>;
99
114
  }
@@ -164,6 +179,11 @@ declare module 'react-native-nfc-manager' {
164
179
  customCommandCode: number;
165
180
  customRequestParameters: number[];
166
181
  }) => Promise<number[]>;
182
+ sendRequest: (params: {
183
+ flags: number;
184
+ commandCode: number;
185
+ data: number[];
186
+ }) => Promise<[number, number[]]>;
167
187
  extendedReadSingleBlock: (params: {
168
188
  flags: number;
169
189
  blockNumber: number;
@@ -206,6 +226,7 @@ declare module 'react-native-nfc-manager' {
206
226
  */
207
227
  ndefHandler: NdefHandler;
208
228
  nfcAHandler: NfcAHandler;
229
+ nfcVHandler: NfcVHandler;
209
230
  isoDepHandler: IsoDepHandler;
210
231
 
211
232
  /**
package/ios/NfcManager.m CHANGED
@@ -1174,6 +1174,39 @@ RCT_EXPORT_METHOD(iso15693_customCommand:(NSDictionary *)options callback:(nonnu
1174
1174
  }
1175
1175
  }
1176
1176
 
1177
+ RCT_EXPORT_METHOD(iso15693_sendRequest:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
1178
+ {
1179
+ if (@available(iOS 14.0, *)) {
1180
+ if (!tagSession || !tagSession.connectedTag) {
1181
+ callback(@[@"Not connected", [NSNull null]]);
1182
+ return;
1183
+ }
1184
+
1185
+ id<NFCISO15693Tag> tag = [tagSession.connectedTag asNFCISO15693Tag];
1186
+ if (!tag) {
1187
+ callback(@[@"incorrect tag type", [NSNull null]]);
1188
+ return;
1189
+ }
1190
+
1191
+ NSInteger flags = [[options objectForKey:@"flags"] integerValue];
1192
+ NSInteger commandCode = [[options objectForKey:@"commandCode"] integerValue];
1193
+ NSData *data = [self arrayToData:[options mutableArrayValueForKey:@"data"]];
1194
+
1195
+ [tag sendRequestWithFlag:flags
1196
+ commandCode:commandCode
1197
+ data:data
1198
+ completionHandler:^(NFCISO15693ResponseFlag responseFlag, NSData *resp, NSError *error) {
1199
+ if (error) {
1200
+ callback(@[getErrorMessage(error), [NSNull null]]);
1201
+ return;
1202
+ }
1203
+ callback(@[[NSNull null], [NSNumber numberWithLong:responseFlag], [NfcManager dataToArray:resp]]);
1204
+ }];
1205
+ } else {
1206
+ callback(@[@"Not support in this device", [NSNull null]]);
1207
+ }
1208
+ }
1209
+
1177
1210
  RCT_EXPORT_METHOD(iso15693_extendedReadSingleBlock:(NSDictionary *)options callback:(nonnull RCTResponseSenderBlock)callback)
1178
1211
  {
1179
1212
  if (@available(iOS 13.0, *)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nfc-manager",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "description": "A NFC module for react native.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/NfcManager.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  } from './NativeNfcManager';
8
8
  import {NdefHandler, NdefStatus} from './NfcTech/NdefHandler';
9
9
  import {NfcAHandler} from './NfcTech/NfcAHandler';
10
+ import {NfcVHandler} from './NfcTech/NfcVHandler';
10
11
  import {IsoDepHandler} from './NfcTech/IsoDepHandler';
11
12
  import {
12
13
  handleNativeException,
@@ -125,6 +126,13 @@ class NfcManagerBase {
125
126
  return this._nfcAHandler;
126
127
  }
127
128
 
129
+ get nfcVHandler() {
130
+ if (!this._nfcVHandler) {
131
+ this._nfcVHandler = new NfcVHandler();
132
+ }
133
+ return this._nfcVHandler;
134
+ }
135
+
128
136
  get isoDepHandler() {
129
137
  if (!this._isoDepHandler) {
130
138
  this._isoDepHandler = new IsoDepHandler();
@@ -8,6 +8,7 @@ import {
8
8
  } from './NfcManager';
9
9
  import {
10
10
  Nfc15693RequestFlagIOS,
11
+ Nfc15693ResponseFlagIOS,
11
12
  Iso15693HandlerIOS,
12
13
  } from './NfcTech/Iso15693HandlerIOS';
13
14
  import {handleNativeException} from './NfcError';
@@ -30,6 +31,8 @@ class NfcManagerIOS extends NfcManagerBase {
30
31
  for (const t of tech) {
31
32
  if (t === NfcTech.NfcA) {
32
33
  techList.push(NfcTech.MifareIOS);
34
+ } else if (t === NfcTech.NfcV) {
35
+ techList.push(NfcTech.Iso15693IOS);
33
36
  } else {
34
37
  techList.push(t);
35
38
  }
@@ -145,4 +148,4 @@ class NfcManagerIOS extends NfcManagerBase {
145
148
  }
146
149
  }
147
150
 
148
- export {NfcManagerIOS, Nfc15693RequestFlagIOS};
151
+ export {NfcManagerIOS, Nfc15693RequestFlagIOS, Nfc15693ResponseFlagIOS};
@@ -8,6 +8,17 @@ const Nfc15693RequestFlagIOS = {
8
8
  Select: 1 << 4,
9
9
  Address: 1 << 5,
10
10
  Option: 1 << 6,
11
+ CommandSpecificBit8: 1 << 7,
12
+ };
13
+
14
+ const Nfc15693ResponseFlagIOS = {
15
+ Error: 1 << 0,
16
+ ResponseBufferValid: 1 << 1,
17
+ FinalResponse: 1 << 2,
18
+ ProtocolExtension: 1 << 3,
19
+ BlockSecurityStatusBit5: 1 << 4,
20
+ BlockSecurityStatusBit6: 1 << 5,
21
+ WaitTimeExtension: 1 << 6
11
22
  };
12
23
 
13
24
  class Iso15693HandlerIOS {
@@ -87,6 +98,15 @@ class Iso15693HandlerIOS {
87
98
  );
88
99
  }
89
100
 
101
+ // https://developer.apple.com/documentation/corenfc/nfciso15693tag/3551933-sendrequestwithflag?language=objc
102
+ sendRequest({flags, commandCode, data}) {
103
+ return handleNativeException(
104
+ callNative('iso15693_sendRequest', [
105
+ {flags, commandCode, data},
106
+ ]),
107
+ );
108
+ }
109
+
90
110
  extendedReadSingleBlock({flags, blockNumber}) {
91
111
  return handleNativeException(
92
112
  callNative('iso15693_extendedReadSingleBlock', [{flags, blockNumber}]),
@@ -108,4 +128,4 @@ class Iso15693HandlerIOS {
108
128
  }
109
129
  }
110
130
 
111
- export {Nfc15693RequestFlagIOS, Iso15693HandlerIOS};
131
+ export {Nfc15693RequestFlagIOS, Nfc15693ResponseFlagIOS, Iso15693HandlerIOS};
@@ -0,0 +1,39 @@
1
+ import {Platform} from 'react-native';
2
+ import {callNative, NativeNfcManager} from '../NativeNfcManager';
3
+ import {handleNativeException} from '../NfcError';
4
+
5
+ class NfcVHandler {
6
+ async transceive(bytes) {
7
+ if (!Array.isArray(bytes)) {
8
+ throw new Error(
9
+ 'IsoDepHandler.transceive only takes input as a byte array',
10
+ );
11
+ }
12
+
13
+ if (Platform.OS === 'ios') {
14
+ const [flags, commandCode, ...data] = bytes;
15
+ return handleNativeException(
16
+ new Promise((resolve, reject) => {
17
+ NativeNfcManager.iso15693_sendRequest(
18
+ {
19
+ flags,
20
+ commandCode,
21
+ data,
22
+ },
23
+ (err, responseFlag, response) => {
24
+ if (err) {
25
+ reject(err);
26
+ } else {
27
+ resolve([responseFlag, ...response]);
28
+ }
29
+ },
30
+ );
31
+ }),
32
+ );
33
+ }
34
+
35
+ return handleNativeException(callNative('transceive', [bytes]));
36
+ }
37
+ }
38
+
39
+ export {NfcVHandler};
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ import {NfcEvents, NfcTech, NdefStatus} from './NfcManager';
4
4
  import {NfcAdapter, NfcManagerAndroid} from './NfcManagerAndroid';
5
5
  import {
6
6
  Nfc15693RequestFlagIOS,
7
+ Nfc15693ResponseFlagIOS,
7
8
  NfcManagerIOS,
8
9
  } from './NfcManagerIOS';
9
10
  import * as NfcError from './NfcError';
@@ -26,6 +27,7 @@ export {
26
27
  NfcEvents,
27
28
  NfcAdapter,
28
29
  Nfc15693RequestFlagIOS,
30
+ Nfc15693ResponseFlagIOS,
29
31
  Ndef,
30
32
  NdefStatus,
31
33
  NfcError,