@iotize/device-com-nfc.cordova 3.1.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.
Files changed (76) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +673 -0
  3. package/bundles/iotize-device-com-nfc.cordova.umd.js +469 -0
  4. package/bundles/iotize-device-com-nfc.cordova.umd.js.map +1 -0
  5. package/esm2015/iotize-device-com-nfc.cordova.js +5 -0
  6. package/esm2015/iotize-device-com-nfc.cordova.js.map +1 -0
  7. package/esm2015/iotize-device-com-nfc.cordova.metadata.json +1 -0
  8. package/esm2015/iotize-device-com-nfc.cordova.ngsummary.json +1 -0
  9. package/esm2015/public_api.js +2 -0
  10. package/esm2015/public_api.js.map +1 -0
  11. package/esm2015/public_api.metadata.json +1 -0
  12. package/esm2015/public_api.ngsummary.json +1 -0
  13. package/esm2015/www/cordova-interface.js +2 -0
  14. package/esm2015/www/cordova-interface.js.map +1 -0
  15. package/esm2015/www/cordova-interface.metadata.json +1 -0
  16. package/esm2015/www/cordova-interface.ngsummary.json +1 -0
  17. package/esm2015/www/errors.js +28 -0
  18. package/esm2015/www/errors.js.map +1 -0
  19. package/esm2015/www/errors.metadata.json +1 -0
  20. package/esm2015/www/errors.ngsummary.json +1 -0
  21. package/esm2015/www/index.js +5 -0
  22. package/esm2015/www/index.js.map +1 -0
  23. package/esm2015/www/index.metadata.json +1 -0
  24. package/esm2015/www/index.ngsummary.json +1 -0
  25. package/esm2015/www/logger.js +3 -0
  26. package/esm2015/www/logger.js.map +1 -0
  27. package/esm2015/www/logger.metadata.json +1 -0
  28. package/esm2015/www/logger.ngsummary.json +1 -0
  29. package/esm2015/www/nfc-com-protocol.js +109 -0
  30. package/esm2015/www/nfc-com-protocol.js.map +1 -0
  31. package/esm2015/www/nfc-com-protocol.metadata.json +1 -0
  32. package/esm2015/www/nfc-com-protocol.ngsummary.json +1 -0
  33. package/esm2015/www/tap-ndef/definitions.js +2 -0
  34. package/esm2015/www/tap-ndef/definitions.js.map +1 -0
  35. package/esm2015/www/tap-ndef/definitions.metadata.json +1 -0
  36. package/esm2015/www/tap-ndef/definitions.ngsummary.json +1 -0
  37. package/esm2015/www/tap-ndef/index.js +3 -0
  38. package/esm2015/www/tap-ndef/index.js.map +1 -0
  39. package/esm2015/www/tap-ndef/index.metadata.json +1 -0
  40. package/esm2015/www/tap-ndef/index.ngsummary.json +1 -0
  41. package/esm2015/www/tap-ndef/parse-ndef-message.js +57 -0
  42. package/esm2015/www/tap-ndef/parse-ndef-message.js.map +1 -0
  43. package/esm2015/www/tap-ndef/parse-ndef-message.metadata.json +1 -0
  44. package/esm2015/www/tap-ndef/parse-ndef-message.ngsummary.json +1 -0
  45. package/fesm2015/iotize-device-com-nfc.cordova.js +196 -0
  46. package/fesm2015/iotize-device-com-nfc.cordova.js.map +1 -0
  47. package/iotize-device-com-nfc.cordova.d.ts +4 -0
  48. package/iotize-device-com-nfc.cordova.metadata.json +1 -0
  49. package/package.json +54 -0
  50. package/plugin.xml +97 -0
  51. package/public_api.d.ts +1 -0
  52. package/src/android/build.gradle +38 -0
  53. package/src/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  54. package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  55. package/src/android/gradlew +172 -0
  56. package/src/android/gradlew.bat +84 -0
  57. package/src/android/local.properties +8 -0
  58. package/src/android/src/com/chariotsolutions/nfc/plugin/JSONBuilder.java +60 -0
  59. package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java +1192 -0
  60. package/src/android/src/com/chariotsolutions/nfc/plugin/NfcPluginError.java +15 -0
  61. package/src/android/src/com/chariotsolutions/nfc/plugin/PluginResponse.java +85 -0
  62. package/src/android/src/com/chariotsolutions/nfc/plugin/Util.java +140 -0
  63. package/src/ios/AppDelegate+NFC.swift +51 -0
  64. package/src/ios/ISO15Reader.swift +376 -0
  65. package/src/ios/NFCNDEFDelegate.swift +78 -0
  66. package/src/ios/NFCPlugin-Bridging-Header.h +7 -0
  67. package/src/ios/NFCTapPlugin.swift +251 -0
  68. package/www/cordova-interface.d.ts +18 -0
  69. package/www/errors.d.ts +16 -0
  70. package/www/index.d.ts +4 -0
  71. package/www/logger.d.ts +2 -0
  72. package/www/nfc-com-protocol.d.ts +14 -0
  73. package/www/phonegap-nfc.js +885 -0
  74. package/www/tap-ndef/definitions.d.ts +25 -0
  75. package/www/tap-ndef/index.d.ts +2 -0
  76. package/www/tap-ndef/parse-ndef-message.d.ts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ Copyright 2019 IoTize SAS
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
9
+ -----
10
+
11
+ The MIT License
12
+
13
+ Copyright (c) 2011-2017 Chariot Solutions
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to deal
17
+ in the Software without restriction, including without limitation the rights
18
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in
23
+ all copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,673 @@
1
+ # IoTize PhoneGap NFC iPhone XR / XS support
2
+
3
+ This is a fork from [PhoneGap NFC Plugin 1.0.3](https://github.com/chariotsolutions/phonegap-nfc)
4
+
5
+ ## Ionic support
6
+
7
+ You can use this plugin with the ionic-native NFC provider:
8
+ ```bash
9
+ npm i @ionic-native/nfc
10
+ ```
11
+ Note: the iOS method `beginNDEFSession` is not referenced in `@ionic-native/nfc`. In order to call this method within an Ionic project, you need to declare it within your typescript file:
12
+
13
+ ```typescript
14
+ declare var nfc: Any;
15
+
16
+ nfc.beginNDEFSession(success, failure);
17
+ ```
18
+ ## IoTize NFC Com Protocol
19
+
20
+ The current plugin comes with a protocol that allows to use NFC ISO15693 compatible devices to communicate with IoTize products.
21
+
22
+ see [Communication protocol](http://developer.iotize.com/content/device-api/communication-protocol/) for more informations
23
+
24
+
25
+ ## Edit AndroidManifest using config.xml
26
+
27
+ Using cordova config-file node, you may edit AndroidManifest.xml file when adding the android platform. Copy the following snippet and add it inside the ```<platform name="android">``` node of your project's config.xml file:
28
+
29
+ ```xml
30
+ <config-file parent="/manifest/application/activity[@android:name='MainActivity']" target="app/src/main/AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
31
+ <intent-filter>
32
+ <action android:name="android.nfc.action.NDEF_DISCOVERED" />
33
+ <category android:name="android.intent.category.DEFAULT" />
34
+ <data android:mimeType="application/YOUR_APPLICATION_PACKAGE" />
35
+ </intent-filter>
36
+ </config-file>
37
+ ```
38
+
39
+ Replace YOUR_APPLICATION_PACKAGE according to your application and IoTize tap configuration.
40
+
41
+ IoTize Cordova NFC Plugin
42
+ ==========================
43
+
44
+ The NFC plugin allows you to read and communicate with IoTize NFC Taps.
45
+
46
+ This plugin uses NDEF (NFC Data Exchange Format) and ISO15693 custom commands
47
+
48
+ Supported Platforms
49
+ -------------------
50
+ * Android
51
+ * [iOS 11](#ios-notes)
52
+
53
+ ## Contents
54
+
55
+ * [Installing](#installing)
56
+ * [NFC](#nfc)
57
+ * [NDEF](#ndef)
58
+ - [NdefMessage](#ndefmessage)
59
+ - [NdefRecord](#ndefrecord)
60
+ * [Events](#events)
61
+ * [Platform Differences](#platform-differences)
62
+ * [Launching Application when Scanning a Tag](#launching-your-android-application-when-scanning-a-tag)
63
+ * [Testing](#testing)
64
+ * [License](#license)
65
+
66
+ # Installing
67
+
68
+ ### Cordova
69
+
70
+ $ cordova plugin add @iotize/device-com-nfc.cordova
71
+
72
+ ## iOS Notes
73
+
74
+ Reading NFC NDEF tags is supported on iPhone 7 and iPhone 7 Plus running iOS 11. To enable your app to detect NFC tags, the plugin adds the Near Field Communication Tag Reading capability in your Xcode project. You must build your application with XCode 9+. See the [Apple Documentation](http://help.apple.com/xcode/mac/current/#/dev88ff319e7) for more info.
75
+
76
+ Use [nfc.addNdefListener](#nfcaddndeflistener) to read NDEF NFC tags with iOS. Unfortunately, iOS also requires you to begin a session before scanning NFC tag. The JavaScript API contains two iOS specific function [nfc.beginNDEFSession](#nfcgbeginndefsession) and [nfc.invalidateNDEFSession](#nfcinvalidatendefsession)
77
+
78
+ You must call [nfc.beginNDEFSession](#nfcgbeginndefsession) before every scan.
79
+
80
+ ### *iOS 13 Beta*
81
+
82
+ With iOS 13, Apple opened its NFC API and allowed communication with ISO15693 tags.
83
+
84
+ Use [nfc.connect](#nfcconnect) to begin a NFC communication session in your iOS app. you may then use the [nfc.transceive](#nfctransceive) method to exchange, and then close the session with [nfc.close](#nfcclose)
85
+
86
+ # NFC
87
+
88
+ > The nfc object provides access to the device's NFC sensor.
89
+
90
+ ## Methods
91
+
92
+ - [nfc.addNdefListener](#nfcaddndeflistener)
93
+ - [nfc.addMimeTypeListener](#nfcaddmimetypelistener)
94
+ - [nfc.enabled](#nfcenabled)
95
+ - [nfc.showSettings](#nfcshowsettings)
96
+ - [nfc.beginNDEFSession](#beginndefsession)
97
+ - [nfc.invalidateNDEFSession](#nfcinvalidatendefsession)
98
+
99
+ ## Tag Technology Functions
100
+
101
+ - [nfc.connect](#nfcconnect)
102
+ - [nfc.transceive](#nfctransceive)
103
+ - [nfc.close](#nfcclose)
104
+
105
+ ## nfc.addNdefListener
106
+
107
+ Registers an event listener for any NDEF tag.
108
+
109
+ nfc.addNdefListener(callback, [onSuccess], [onFailure]);
110
+
111
+ ### Parameters
112
+
113
+ - __callback__: The callback that is called when an NDEF tag is read.
114
+ - __onSuccess__: (Optional) The callback that is called when the listener is added.
115
+ - __onFailure__: (Optional) The callback that is called if there was an error.
116
+
117
+ ### Description
118
+
119
+ Function `nfc.addNdefListener` registers the callback for ndef events.
120
+
121
+ A ndef event is fired when a NDEF tag is read.
122
+
123
+ For BlackBerry 10, you must configure the type of tags your application will read with an [invoke-target in config.xml](#blackberry-10-invoke-target).
124
+
125
+ On Android registered [mimeTypeListeners](#nfcaddmimetypelistener) takes precedence over this more generic NDEF listener.
126
+
127
+ On iOS you must call [beginNDEFSession](#nfcbeginndefsession) before scanning a NDEF tag.
128
+
129
+ ### Supported Platforms
130
+
131
+ - Android
132
+ - iOS
133
+
134
+ ## nfc.removeNdefListener
135
+
136
+ Removes the previously registered event listener for NDEF tags added via `nfc.addNdefListener`.
137
+
138
+ nfc.removeNdefListener(callback, [onSuccess], [onFailure]);
139
+
140
+ Removing listeners is not recommended. Instead, consider that your callback can ignore messages you no longer need.
141
+
142
+ ### Parameters
143
+
144
+ - __callback__: The previously registered callback.
145
+ - __onSuccess__: (Optional) The callback that is called when the listener is successfully removed.
146
+ - __onFailure__: (Optional) The callback that is called if there was an error during removal.
147
+
148
+ ### Supported Platforms
149
+
150
+ - Android
151
+ - iOS
152
+
153
+
154
+ ## nfc.addTapDeviceListener
155
+
156
+ Registers an event listener for NFC tap
157
+
158
+ ```
159
+ nfc.addTapDeviceListener([onSuccess], [onFailure]);
160
+ ```
161
+
162
+ Related preference:
163
+
164
+ - `boolean` **EnableEncryptionWithNFC** true to enable encryption when connecting to a new Tap.
165
+ - `boolean` **EnableNFCPairing** true to enable NFC pairing when connecting to a new Tap
166
+ - `boolean` **EnableNFCTapDeviceDiscovery** true to enable NFC Tap discovery in the native part of the plugin.
167
+ - `string` **NFCTapDeviceMimeType** app mime type. Eg: `application/com.iotize.apps.tapmanager`
168
+ - `string` **NFCParingDoneToastMessage** toast messsage displayed when NFC pairing has been done. Give an empty string to disable this message.
169
+ -
170
+ ### Supported Platforms
171
+
172
+ - Android
173
+
174
+ ## nfc.addMimeTypeListener
175
+
176
+ Registers an event listener for NDEF tags matching a specified MIME type.
177
+
178
+ nfc.addMimeTypeListener(mimeType, callback, [onSuccess], [onFailure]);
179
+
180
+ ### Parameters
181
+
182
+ - __mimeType__: The MIME type to filter for messages.
183
+ - __callback__: The callback that is called when an NDEF tag matching the MIME type is read.
184
+ - __onSuccess__: (Optional) The callback that is called when the listener is added.
185
+ - __onFailure__: (Optional) The callback that is called if there was an error.
186
+
187
+ ### Description
188
+
189
+ Function `nfc.addMimeTypeListener` registers the callback for ndef-mime events.
190
+
191
+ A ndef-mime event occurs when a `Ndef.TNF_MIME_MEDIA` tag is read and matches the specified MIME type.
192
+
193
+ This function can be called multiple times to register different MIME types. You should use the *same* handler for all MIME messages.
194
+
195
+ nfc.addMimeTypeListener("text/json", *onNfc*, success, failure);
196
+ nfc.addMimeTypeListener("text/demo", *onNfc*, success, failure);
197
+
198
+ On Android, MIME types for filtering should always be lower case. (See [IntentFilter.addDataType()](http://developer.android.com/reference/android/content/IntentFilter.html#addDataType\(java.lang.String\)))
199
+
200
+ ### Supported Platforms
201
+
202
+ - Android
203
+
204
+ ## nfc.removeMimeTypeListener
205
+
206
+ Removes the previously registered event listener added via `nfc.addMimeTypeListener`.
207
+
208
+ nfc.removeMimeTypeListener(mimeType, callback, [onSuccess], [onFailure]);
209
+
210
+ Removing listeners is not recommended. Instead, consider that your callback can ignore messages you no longer need.
211
+
212
+ ### Parameters
213
+
214
+ - __mimeType__: The MIME type to filter for messages.
215
+ - __callback__: The previously registered callback.
216
+ - __onSuccess__: (Optional) The callback that is called when the listener is successfully removed.
217
+ - __onFailure__: (Optional) The callback that is called if there was an error during removal.
218
+
219
+ ### Supported Platforms
220
+
221
+ - Android
222
+
223
+
224
+ ## nfc.showSettings
225
+
226
+ Show the NFC settings on the device.
227
+
228
+ nfc.showSettings(success, failure);
229
+
230
+ ### Description
231
+
232
+ Function `showSettings` opens the NFC settings for the operating system.
233
+
234
+ ### Parameters
235
+
236
+ - __success__: Success callback function [optional]
237
+ - __failure__: Error callback function, invoked when error occurs. [optional]
238
+
239
+ ### Quick Example
240
+
241
+ nfc.showSettings();
242
+
243
+ ### Supported Platforms
244
+
245
+ - Android
246
+
247
+ ## nfc.enabled
248
+
249
+ Check if NFC is available and enabled on this device.
250
+
251
+ nfc.enabled(onSuccess, onFailure);
252
+
253
+ ### Parameters
254
+
255
+ - __onSuccess__: The callback that is called when NFC is enabled.
256
+ - __onFailure__: The callback that is called when NFC is disabled or missing.
257
+
258
+ ### Description
259
+
260
+ Function `nfc.enabled` explicitly checks to see if the phone has NFC and if NFC is enabled. If
261
+ everything is OK, the success callback is called. If there is a problem, the failure callback
262
+ will be called with a reason code.
263
+
264
+ The reason will be **NO_NFC** if the device doesn't support NFC and **NFC_DISABLED** if the user has disabled NFC.
265
+
266
+ Note: that on Android the NFC status is checked before every API call **NO_NFC** or **NFC_DISABLED** can be returned in **any** failure function.
267
+
268
+ ### Supported Platforms
269
+
270
+ - Android
271
+ - iOS
272
+
273
+ ## nfc.beginNDEFSession
274
+
275
+ iOS requires you to begin a session before scanning a NFC tag.
276
+
277
+ nfc.beginNDEFSession(success, failure);
278
+
279
+ ### Description
280
+
281
+ Function `beginNDEFSession` starts the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) allowing iOS to scan NFC tags.
282
+
283
+ If the session is closed by the user, it will trigger the Error callback (if it exists)
284
+
285
+ ### Parameters
286
+
287
+ - __success__: Success callback function called when the session begins [optional]
288
+ - __failure__: Error callback function, invoked when error occurs. [optional]
289
+
290
+ ### Quick Example
291
+
292
+ nfc.beginNDEFSession();
293
+
294
+ ### Supported Platforms
295
+
296
+ - iOS
297
+
298
+ ## nfc.invalidateSession
299
+
300
+ Invalidate the NFC NDEF session.
301
+
302
+ nfc.invalidateSession(success, failure);
303
+
304
+ ### Description
305
+
306
+ Function `invalidateSession` stops the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) returning control to your app.
307
+
308
+ ### Parameters
309
+
310
+ - __success__: Success callback function called when the session in invalidated [optional]
311
+ - __failure__: Error callback function, invoked when error occurs. [optional]
312
+
313
+ ### Quick Example
314
+
315
+ nfc.invalidateSession();
316
+
317
+ ### Supported Platforms
318
+
319
+ - iOS
320
+
321
+ # Tag Technology Functions
322
+
323
+ This plugin is built to communicate with IoTize tags. See the original plugin if you need a more complete use of the NFC
324
+
325
+ [PhoneGap NFC Plugin 1.0.3](https://github.com/chariotsolutions/phonegap-nfc)
326
+
327
+ ## nfc.connect
328
+
329
+ Connect to the tag and enable I/O operations to the tag from this TagTechnology object.
330
+
331
+ ```typescript
332
+ //Android
333
+ nfc.connect(tech);
334
+
335
+ nfc.connect(tech, timeout);
336
+
337
+ //iOS
338
+ nfc.connect()
339
+ ````
340
+
341
+ ### Description
342
+
343
+ Function `connect` enables I/O operations to the tag from this TagTechnology object. `nfc.connect` should be called after receiving a nfcEvent from the `addNdefListener`. Only one TagTechnology object can be connected to a Tag at a time.
344
+
345
+ See Android's [TagTechnology.connect()](https://developer.android.com/reference/android/nfc/tech/TagTechnology.html#connect()) for more info.
346
+
347
+ On iOS, `connect` starts a NFC Session, and is resolved when the device is connected to a Tag.
348
+
349
+ ### Parameters (Android only)
350
+
351
+ - __tech__: The tag technology e.g. android.nfc.tech.IsoDep
352
+ - __timeout__: The transceive(byte[]) timeout in milliseconds [optional]
353
+
354
+ ### Returns
355
+
356
+ - Promise when the connection is successful
357
+
358
+ ### Quick Example
359
+ ```typescript
360
+ nfc.addTagDiscoveredListener(function(nfcEvent) {
361
+ nfc.connect('android.nfc.tech.IsoDep', 500).then(
362
+ () => console.log('connected to', nfc.bytesToHexString(nfcEvent.tag.id)),
363
+ (error) => console.log('connection failed', error)
364
+ );
365
+ })
366
+ ```
367
+ ### Supported Platforms
368
+
369
+ - Android
370
+ - iOS 13 (beta)
371
+
372
+ ## nfc.transceive
373
+
374
+ Send raw command to the tag and receive the response.
375
+
376
+ nfc.transceive(data);
377
+
378
+ ### Description
379
+
380
+ Function `transceive` sends raw commands to the tag and receives the response. `nfc.connect` must be called before calling `transceive`. Data passed to transceive can be a hex string representation of bytes or an ArrayBuffer. The response is returned as an ArrayBuffer in the promise.
381
+
382
+ See Android's documentation [IsoDep.transceive()](https://developer.android.com/reference/android/nfc/tech/IsoDep.html#transceive(byte[])), [NfcV.transceive()](https://developer.android.com/reference/android/nfc/tech/NfcV.html#transceive(byte[])), [MifareUltralight.transceive()](https://developer.android.com/reference/android/nfc/tech/MifareUltralight.html#transceive(byte[])) for more info.
383
+
384
+ ### Parameters
385
+
386
+ - __data__: a string of hex data or an ArrayBuffer
387
+
388
+ ### Returns
389
+
390
+ - Promise with the response data as an ArrayBuffer
391
+
392
+ ### Quick Example
393
+
394
+ // Promise style
395
+ nfc.transceive('90 5A 00 00 03 AA AA AA 00').then(
396
+ response => console.log(util.arrayBufferToString(response)),
397
+ error => console.log('Error selecting DESFire application')
398
+ )
399
+
400
+ // async await
401
+ const response = await nfc.transceive('90 5A 00 00 03 AA AA AA 00');
402
+ console.log('response =',util.arrayBufferToString(response));
403
+
404
+ ### Supported Platforms
405
+
406
+ - Android
407
+ - iOS 13 (beta)
408
+
409
+ ## nfc.close
410
+
411
+ Close TagTechnology connection.
412
+
413
+ nfc.close();
414
+
415
+ ### Description
416
+
417
+ Function `close` disabled I/O operations to the tag from this TagTechnology object, and releases resources.
418
+
419
+ See Android's [TagTechnology.close()](https://developer.android.com/reference/android/nfc/tech/TagTechnology.html#close()) for more info.
420
+
421
+ ### Parameters
422
+
423
+ - none
424
+
425
+ ### Returns
426
+
427
+ - Promise when the connection is successfully closed
428
+
429
+ ### Quick Example
430
+
431
+ nfc.transceive().then(
432
+ () => console.log('connection closed'),
433
+ (error) => console.log('error closing connection', error);
434
+ )
435
+
436
+ ### Supported Platforms
437
+
438
+ - Android
439
+ - iOS 13 (beta)
440
+
441
+ # NDEF
442
+
443
+ > The `ndef` object provides NDEF constants, functions for creating NdefRecords, and functions for converting data.
444
+ > See [android.nfc.NdefRecord](http://developer.android.com/reference/android/nfc/NdefRecord.html) for documentation about constants
445
+
446
+ ## NdefMessage
447
+
448
+ Represents an NDEF (NFC Data Exchange Format) data message that contains one or more NdefRecords.
449
+ This plugin uses an array of NdefRecords to represent an NdefMessage.
450
+
451
+ ## NdefRecord
452
+
453
+ Represents a logical (unchunked) NDEF (NFC Data Exchange Format) record.
454
+
455
+ ### Properties
456
+
457
+ - __tnf__: 3-bit TNF (Type Name Format) - use one of the TNF_* constants
458
+ - __type__: byte array, containing zero to 255 bytes, must not be null
459
+ - __id__: byte array, containing zero to 255 bytes, must not be null
460
+ - __payload__: byte array, containing zero to (2 ** 32 - 1) bytes, must not be null
461
+
462
+ The `ndef` object has a function for creating NdefRecords
463
+
464
+ var type = "text/pg",
465
+ id = [],
466
+ payload = nfc.stringToBytes("Hello World"),
467
+ record = ndef.record(ndef.TNF_MIME_MEDIA, type, id, payload);
468
+
469
+ There are also helper functions for some types of records
470
+
471
+ Create a URI record
472
+
473
+ var record = ndef.uriRecord("http://chariotsolutions.com");
474
+
475
+ Create a plain text record
476
+
477
+ var record = ndef.textRecord("Plain text message");
478
+
479
+ Create a mime type record
480
+
481
+ var mimeType = "text/pg",
482
+ payload = "Hello Phongap",
483
+ record = ndef.mimeMediaRecord(mimeType, nfc.stringToBytes(payload));
484
+
485
+ Create an Empty record
486
+
487
+ var record = ndef.emptyRecord();
488
+
489
+ Create an Android Application Record (AAR)
490
+
491
+ var record = ndef.androidApplicationRecord('com.example');
492
+
493
+ See `ndef.record`, `ndef.textRecord`, `ndef.mimeMediaRecord`, and `ndef.uriRecord`.
494
+
495
+ The Ndef object has functions to convert some data types to and from byte arrays.
496
+
497
+ See the [phonegap-nfc.js](https://github.com/chariotsolutions/phonegap-nfc/blob/master/www/phonegap-nfc.js) source for more documentation.
498
+
499
+ # Events
500
+
501
+ Events are fired when NFC tags are read. Listeners are added by registering callback functions with the `nfc` object. For example ` nfc.addNdefListener(myNfcListener, win, fail);`
502
+
503
+ ## NfcEvent
504
+
505
+ ### Properties
506
+
507
+ - __type__: event type
508
+ - __tag__: Ndef tag
509
+
510
+ ### Types
511
+
512
+ - ndef-mime
513
+ - ndef
514
+
515
+ The tag contents are platform dependent.
516
+
517
+ `id` and `techTypes` may be included when scanning a tag on Android.
518
+
519
+ Assuming the following NDEF message is written to a tag, it will produce the following events when read.
520
+
521
+ var ndefMessage = [
522
+ ndef.createMimeRecord('text/pg', 'Hello PhoneGap')
523
+ ];
524
+
525
+ #### Sample Event on Android
526
+
527
+ {
528
+ type: 'ndef',
529
+ tag: {
530
+ "isWritable": true,
531
+ "id": [4, 96, 117, 74, -17, 34, -128],
532
+ "techTypes": ["android.nfc.tech.IsoDep", "android.nfc.tech.NfcA", "android.nfc.tech.Ndef"],
533
+ "type": "NFC Forum Type 4",
534
+ "canMakeReadOnly": false,
535
+ "maxSize": 2046,
536
+ "ndefMessage": [{
537
+ "id": [],
538
+ "type": [116, 101, 120, 116, 47, 112, 103],
539
+ "payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112],
540
+ "tnf": 2
541
+ }]
542
+ }
543
+ }
544
+
545
+ #### Sample Event on iOS
546
+
547
+ {
548
+ type: 'ndef',
549
+ tag: {
550
+ "ndefMessage": [{
551
+ "tnf": 2,
552
+ "type": [116, 101, 120, 116, 47, 112, 103],
553
+ "id": [],
554
+ "payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112]
555
+ }]
556
+ }
557
+ }
558
+
559
+ ## Getting Details about Events
560
+
561
+ The raw contents of the scanned tags are written to the log before the event is fired. Use `adb logcat` on Android
562
+
563
+ You can also log the tag contents in your event handlers. `console.log(JSON.stringify(nfcEvent.tag))` Note that you want to stringify the tag not the event to avoid a circular reference.
564
+
565
+ # Platform Differences
566
+
567
+ ## Multiple Listeners
568
+
569
+ Multiple listeners can be registered in JavaScript. e.g. addNdefListener, addTagDiscoveredListener, addMimeTypeListener.
570
+
571
+ On Android, only the most specific event will fire. If a Mime Media Tag is scanned, only the addMimeTypeListener callback is called and not the callback defined in addNdefListener. You can use the same event handler for multiple listeners.
572
+
573
+ On iOS, events are fired as NDEF ones. If the application has been launched with a NFC Tag, the scanned NDEF will be fired as soon as the addNdefListener has been called
574
+
575
+ # Launching your Application when Scanning a Tag
576
+
577
+ ## Android
578
+
579
+ On Android, intents can be used to launch your application when a NFC tag is read. This is optional and configured in AndroidManifest.xml.
580
+
581
+ <intent-filter>
582
+ <action android:name="android.nfc.action.NDEF_DISCOVERED" />
583
+ <data android:mimeType="text/pg" />
584
+ <category android:name="android.intent.category.DEFAULT" />
585
+ </intent-filter>
586
+
587
+ Note: `data android:mimeType="text/pg"` should match the data type you specified in JavaScript
588
+
589
+ We have found it necessary to add `android:noHistory="true"` to the activity element so that scanning a tag launches the application after the user has pressed the home button.
590
+
591
+ See the Android documentation for more information about [filtering for NFC intents](http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#ndef-disc).
592
+
593
+ ## iOS:
594
+
595
+ With the proper configuration, it is now possible to launch a phoneGap / cordova app by reading a NFC NDEF Tag.
596
+
597
+ When a tag is detected, a notification appears and asks you to open the linked app. It then opens the app (if it is not open yet) and gives the NDEFMessage delivered by the tag.
598
+
599
+ You don't have to start a session anymore (cf [iOS notes](#iOS-Notes)), but you need to accept the notification in order to retrieve the tag's content.
600
+
601
+ This feature is available on iPhone XR / XS / XS Max. earlier devices do not support background tag reading.
602
+
603
+ You will need to turn on *Associated Domains* and *Near Field Communication Tag Reading* capabilities in your Xcode project, support universal links and add the website linked to the app as an *Associated Domain* with the following scheme:
604
+
605
+ applinks:www.example.com
606
+
607
+ Tag delivery is then handled by the plugin.
608
+
609
+ Check out the official documentation for more precise informations.
610
+
611
+ - [Adding support for background tag reading](https://developer.apple.com/documentation/corenfc/adding_support_for_background_tag_reading)
612
+
613
+ - [Support Universal Links](https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html)
614
+
615
+ Testing
616
+ =======
617
+
618
+ Tests require the [Cordova Plugin Test Framework](https://github.com/apache/cordova-plugin-test-framework)
619
+
620
+ Create a new project
621
+
622
+ git clone https://github.com/chariotsolutions/phonegap-nfc
623
+ cordova create nfc-test com.example.nfc.test NfcTest
624
+ cd nfc-test
625
+ cordova platform add android
626
+ cordova plugin add ../phonegap-nfc
627
+ cordova plugin add ../phonegap-nfc/tests
628
+ cordova plugin add https://github.com/apache/cordova-plugin-test-framework.git
629
+
630
+ Change the start page in `config.xml`
631
+
632
+ <content src="cdvtests/index.html" />
633
+
634
+ Run the app on your phone
635
+
636
+ cordova run
637
+
638
+ License
639
+ ================
640
+
641
+ ## IoTize SAS
642
+
643
+ Copyright 2019 IoTize SAS
644
+
645
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
646
+
647
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
648
+
649
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
650
+
651
+ ## Chariot Solutions
652
+
653
+ The MIT License
654
+
655
+ Copyright (c) 2011-2017 Chariot Solutions
656
+
657
+ Permission is hereby granted, free of charge, to any person obtaining a copy
658
+ of this software and associated documentation files (the "Software"), to deal
659
+ in the Software without restriction, including without limitation the rights
660
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
661
+ copies of the Software, and to permit persons to whom the Software is
662
+ furnished to do so, subject to the following conditions:
663
+
664
+ The above copyright notice and this permission notice shall be included in
665
+ all copies or substantial portions of the Software.
666
+
667
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
668
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
669
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
670
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
671
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
672
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
673
+ THE SOFTWARE.