community-cordova-plugin-nfc 1.3.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/README.md ADDED
@@ -0,0 +1,1371 @@
1
+ [![NPM version](https://img.shields.io/npm/v/community-cordova-plugin-nfc)](https://www.npmjs.com/package/community-cordova-plugin-nfc)
2
+
3
+ #### This is a fork of the original plugin phonegap-nfc
4
+
5
+ # community-cordova-plugin-nfc
6
+
7
+
8
+ I dedicate a considerable amount of my free time to developing and maintaining many cordova plugins for the community ([See the list with all my maintained plugins][community_plugins]).
9
+ To help ensure this plugin is kept updated,
10
+ new features are added and bugfixes are implemented quickly,
11
+ please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance.
12
+ Please consider donating if you're using this plugin in an app that makes you money,
13
+ or if you're asking for new features or priority bug fixes. Thank you!
14
+
15
+ [![](https://img.shields.io/static/v1?label=Sponsor%20Me&style=for-the-badge&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/eyalin)
16
+
17
+
18
+
19
+ The NFC plugin allows you to read and write NFC tags. You can also beam to, and receive from, other NFC enabled devices.
20
+
21
+ Use to
22
+ * read data from NFC tags
23
+ * write data to NFC tags
24
+ * send data to other NFC enabled devices
25
+ * receive data from NFC devices
26
+ * send raw commands (ISO 14443-3A, ISO 14443-3A, ISO 14443-4, JIS 6319-4, ISO 15693) to NFC tags
27
+
28
+ This plugin uses NDEF (NFC Data Exchange Format) for maximum compatibilty between NFC devices, tag types, and operating systems.
29
+
30
+ Supported Platforms
31
+ -------------------
32
+ * Android
33
+ * [iOS 11](#ios-notes)
34
+ * Windows (includes Windows Phone 8.1, Windows 8.1, Windows 10)
35
+ * BlackBerry 10
36
+ * Windows Phone 8
37
+ * BlackBerry 7
38
+
39
+ ## Contents
40
+
41
+ * [Installing](#installing)
42
+ * [NFC](#nfc)
43
+ * [NDEF](#ndef)
44
+ - [NdefMessage](#ndefmessage)
45
+ - [NdefRecord](#ndefrecord)
46
+ * [Events](#events)
47
+ * [Platform Differences](#platform-differences)
48
+ * [BlackBerry 10 Invoke Target](#blackberry-10-invoke-target)
49
+ * [Launching Application when Scanning a Tag](#launching-your-android-application-when-scanning-a-tag)
50
+ * [Testing](#testing)
51
+ * [Sample Projects](#sample-projects)
52
+ * [Host Card Emulation (HCE)](#hce)
53
+ * [Book](#book)
54
+ * [License](#license)
55
+
56
+ # Installing
57
+
58
+ ### Cordova
59
+
60
+ $ cordova plugin add community-cordova-plugin-nfc
61
+
62
+ ### PhoneGap
63
+
64
+ $ phonegap plugin add community-cordova-plugin-nfc
65
+
66
+ ### PhoneGap Build
67
+
68
+ Edit config.xml to install the plugin for [PhoneGap Build](http://build.phonegap.com).
69
+
70
+ <preference name="phonegap-version" value="cli-9.0.0" />
71
+ <plugin name="phonegap-nfc" source="npm" />
72
+
73
+
74
+ Windows Phone 8.1 should use the **windows** platform. The Silverlight based Windows Phone 8 code is no longer being maintained.
75
+
76
+ BlackBerry 7 support is only available for Cordova 2.x. For applications targeting BlackBerry 7, you may need to use an older version of phonegap-nfc.
77
+
78
+ See [Getting Started](https://github.com/chariotsolutions/phonegap-nfc/blob/master/doc/GettingStartedCLI.md) and [Getting Started BlackBerry 10](https://github.com/chariotsolutions/phonegap-nfc/blob/master/doc/GettingStartedBlackberry10.md)for more details.
79
+
80
+ ## iOS Notes
81
+
82
+ Reading NFC NDEF tags is supported on iPhone 7 (and newer) since iOS 11. iOS 13 added support for writing NDEF messages to NFC tags. iOS 13 also adds the ability to get the UID from some NFC tags. On iOS, the user must start a NFC session to scan for a tag. This is different from Android which can constantly scan for NFC tags. The [nfc.scanNdef](#nfcscanndef) and [nfc.scanTag](#nfcscantag) functions start a NFC scanning session. The NFC tag is returned to the caller via a Promise. If your existing code uses the deprecated [nfc.beginSession](#nfcbeginsession), update it to use `nfc.scanNdef`.
83
+
84
+ The `scanNdef` function uses [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) to detect NFC Data Exchange Format (NDEF) tags. `scanTag` uses the newer [NFCTagReaderSession](https://developer.apple.com/documentation/corenfc/nfctagreadersession) available in iOS 13 to detect ISO15693, FeliCa, and MIFARE tags. The `scanTag` function will include the tag UID and tag type for *some* NFC tags along with the NDEF messages. `scanTag` can also read some RFID tags without NDEF messsages. `scanTag` will not scan some NDEF tags including Topaz and Mifare Classic.
85
+
86
+ You must call [nfc.scanNdef](#nfcscanndef) and [nfc.scanTag](#nfcscantag) before every scan.
87
+
88
+ Writing NFC tags on iOS uses the same [nfc.write](#nfcwrite) function as other platforms. Although it's the same function, the behavior is different on iOS. Calling `nfc.write` on an iOS device will start a new scanning session and write data to the scanned tag.
89
+
90
+ # NFC
91
+
92
+ > The nfc object provides access to the device's NFC sensor.
93
+
94
+ ## Methods
95
+
96
+ - [nfc.addNdefListener](#nfcaddndeflistener)
97
+ - [nfc.addTagDiscoveredListener](#nfcaddtagdiscoveredlistener)
98
+ - [nfc.addMimeTypeListener](#nfcaddmimetypelistener)
99
+ - [nfc.addNdefFormatableListener](#nfcaddndefformatablelistener)
100
+ - [nfc.write](#nfcwrite)
101
+ - [nfc.makeReadOnly](#nfcmakereadonly)
102
+ - [nfc.share](#nfcshare)
103
+ - [nfc.unshare](#nfcunshare)
104
+ - [nfc.erase](#nfcerase)
105
+ - [nfc.handover](#nfchandover)
106
+ - [nfc.stopHandover](#nfcstophandover)
107
+ - [nfc.enabled](#nfcenabled)
108
+ - [nfc.showSettings](#nfcshowsettings)
109
+ - [~~nfc.beginSession~~](#nfcbeginsession)
110
+ - [~~nfc.invalidateSession~~](#nfcinvalidatesession)
111
+ - [nfc.scanNdef](#nfcscanndef)
112
+ - [nfc.scanTag](#nfcscanTag)
113
+ - [nfc.cancelScan](#nfccancelscan)
114
+
115
+ ## ReaderMode
116
+
117
+ - [nfc.readerMode](#nfcreadermode)
118
+ - [nfc.disableReaderMode](#nfcdisablereadermode)
119
+
120
+ ## Tag Technology Functions
121
+
122
+ - [nfc.connect](#nfcconnect)
123
+ - [nfc.transceive](#nfctransceive)
124
+ - [nfc.close](#nfcclose)
125
+ - [ISO-DEP example](#tag-technology-functions-1)
126
+
127
+ ## nfc.addNdefListener
128
+
129
+ Registers an event listener for any NDEF tag.
130
+
131
+ nfc.addNdefListener(callback, [onSuccess], [onFailure]);
132
+
133
+ ### Parameters
134
+
135
+ - __callback__: The callback that is called when an NDEF tag is read.
136
+ - __onSuccess__: (Optional) The callback that is called when the listener is added.
137
+ - __onFailure__: (Optional) The callback that is called if there was an error.
138
+
139
+ ### Description
140
+
141
+ Function `nfc.addNdefListener` registers the callback for ndef events.
142
+
143
+ A ndef event is fired when a NDEF tag is read.
144
+
145
+ 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).
146
+
147
+ On Android registered [mimeTypeListeners](#nfcaddmimetypelistener) takes precedence over this more generic NDEF listener.
148
+
149
+ On iOS you must call [beingSession](#nfcbeginsession) before scanning a tag.
150
+
151
+ ### Supported Platforms
152
+
153
+ - Android
154
+ - iOS
155
+ - Windows
156
+ - BlackBerry 7
157
+ - BlackBerry 10
158
+ - Windows Phone 8
159
+
160
+ ## nfc.removeNdefListener
161
+
162
+ Removes the previously registered event listener for NDEF tags added via `nfc.addNdefListener`.
163
+
164
+ nfc.removeNdefListener(callback, [onSuccess], [onFailure]);
165
+
166
+ Removing listeners is not recommended. Instead, consider that your callback can ignore messages you no longer need.
167
+
168
+ ### Parameters
169
+
170
+ - __callback__: The previously registered callback.
171
+ - __onSuccess__: (Optional) The callback that is called when the listener is successfully removed.
172
+ - __onFailure__: (Optional) The callback that is called if there was an error during removal.
173
+
174
+ ### Supported Platforms
175
+
176
+ - Android
177
+ - iOS
178
+ - Windows
179
+ - BlackBerry 7
180
+
181
+ ## nfc.addTagDiscoveredListener
182
+
183
+ Registers an event listener for tags matching any tag type.
184
+
185
+ nfc.addTagDiscoveredListener(callback, [onSuccess], [onFailure]);
186
+
187
+ ### Parameters
188
+
189
+ - __callback__: The callback that is called when a tag is detected.
190
+ - __onSuccess__: (Optional) The callback that is called when the listener is added.
191
+ - __onFailure__: (Optional) The callback that is called if there was an error.
192
+
193
+ ### Description
194
+
195
+ Function `nfc.addTagDiscoveredListener` registers the callback for tag events.
196
+
197
+ This event occurs when any tag is detected by the phone.
198
+
199
+ ### Supported Platforms
200
+
201
+ - Android
202
+ - Windows
203
+ - BlackBerry 7
204
+
205
+ Note that Windows Phones need the newere NXP PN427 chipset to read non-NDEF tags. That tag will be read, but no tag meta-data is available.
206
+
207
+ ## nfc.removeTagDiscoveredListener
208
+
209
+ Removes the previously registered event listener added via `nfc.addTagDiscoveredListener`.
210
+
211
+ nfc.removeTagDiscoveredListener(callback, [onSuccess], [onFailure]);
212
+
213
+ Removing listeners is not recommended. Instead, consider that your callback can ignore messages you no longer need.
214
+
215
+ ### Parameters
216
+
217
+ - __callback__: The previously registered callback.
218
+ - __onSuccess__: (Optional) The callback that is called when the listener is successfully removed.
219
+ - __onFailure__: (Optional) The callback that is called if there was an error during removal.
220
+
221
+ ### Supported Platforms
222
+
223
+ - Android
224
+ - Windows
225
+ - BlackBerry 7
226
+
227
+ ## nfc.addMimeTypeListener
228
+
229
+ Registers an event listener for NDEF tags matching a specified MIME type.
230
+
231
+ nfc.addMimeTypeListener(mimeType, callback, [onSuccess], [onFailure]);
232
+
233
+ ### Parameters
234
+
235
+ - __mimeType__: The MIME type to filter for messages.
236
+ - __callback__: The callback that is called when an NDEF tag matching the MIME type is read.
237
+ - __onSuccess__: (Optional) The callback that is called when the listener is added.
238
+ - __onFailure__: (Optional) The callback that is called if there was an error.
239
+
240
+ ### Description
241
+
242
+ Function `nfc.addMimeTypeListener` registers the callback for ndef-mime events.
243
+
244
+ A ndef-mime event occurs when a `Ndef.TNF_MIME_MEDIA` tag is read and matches the specified MIME type.
245
+
246
+ This function can be called multiple times to register different MIME types. You should use the *same* handler for all MIME messages.
247
+
248
+ nfc.addMimeTypeListener("text/json", *onNfc*, success, failure);
249
+ nfc.addMimeTypeListener("text/demo", *onNfc*, success, failure);
250
+
251
+ 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\)))
252
+
253
+ ### Supported Platforms
254
+
255
+ - Android
256
+ - BlackBerry 7
257
+
258
+ ## nfc.removeMimeTypeListener
259
+
260
+ Removes the previously registered event listener added via `nfc.addMimeTypeListener`.
261
+
262
+ nfc.removeMimeTypeListener(mimeType, callback, [onSuccess], [onFailure]);
263
+
264
+ Removing listeners is not recommended. Instead, consider that your callback can ignore messages you no longer need.
265
+
266
+ ### Parameters
267
+
268
+ - __mimeType__: The MIME type to filter for messages.
269
+ - __callback__: The previously registered callback.
270
+ - __onSuccess__: (Optional) The callback that is called when the listener is successfully removed.
271
+ - __onFailure__: (Optional) The callback that is called if there was an error during removal.
272
+
273
+ ### Supported Platforms
274
+
275
+ - Android
276
+ - BlackBerry 7
277
+
278
+ ## nfc.addNdefFormatableListener
279
+
280
+ Registers an event listener for formatable NDEF tags.
281
+
282
+ nfc.addNdefFormatableListener(callback, [onSuccess], [onFailure]);
283
+
284
+ ### Parameters
285
+
286
+ - __callback__: The callback that is called when NDEF formatable tag is read.
287
+ - __onSuccess__: (Optional) The callback that is called when the listener is added.
288
+ - __onFailure__: (Optional) The callback that is called if there was an error.
289
+
290
+ ### Description
291
+
292
+ Function `nfc.addNdefFormatableListener` registers the callback for ndef-formatable events.
293
+
294
+ A ndef-formatable event occurs when a tag is read that can be NDEF formatted. This is not fired for tags that are already formatted as NDEF. The ndef-formatable event will not contain an NdefMessage.
295
+
296
+ ### Supported Platforms
297
+
298
+ - Android
299
+
300
+ ## nfc.write
301
+
302
+ Writes an NDEF Message to a NFC tag.
303
+
304
+ A NDEF Message is an array of one or more NDEF Records
305
+
306
+ var message = [
307
+ ndef.textRecord("hello, world"),
308
+ ndef.uriRecord("http://github.com/chariotsolutions/phonegap-nfc")
309
+ ];
310
+
311
+ nfc.write(message, [onSuccess], [onFailure]);
312
+
313
+ ### Parameters
314
+
315
+ - __ndefMessage__: An array of NDEF Records.
316
+ - __onSuccess__: (Optional) The callback that is called when the tag is written.
317
+ - __onFailure__: (Optional) The callback that is called if there was an error.
318
+
319
+ ### Description
320
+
321
+ Function `nfc.write` writes an NdefMessage to a NFC tag.
322
+
323
+ On **Android** this method *must* be called from within an NDEF Event Handler.
324
+
325
+ On **iOS** this method can be called outside the NDEF Event Handler, it will start a new scanning session. Optionally you can reuse the read session to write data. See example below.
326
+
327
+ On **Windows** this method *may* be called from within the NDEF Event Handler.
328
+
329
+ On **Windows Phone 8.1** this method should be called outside the NDEF Event Handler, otherwise Windows tries to read the tag contents as you are writing to the tag.
330
+
331
+ ### Examples
332
+
333
+ #### Android
334
+
335
+ On Android, write must be called inside an event handler
336
+
337
+ function onNfc(nfcEvent) {
338
+
339
+ console.log(nfcEvent.tag);
340
+
341
+ var message = [
342
+ ndef.textRecord(new String(new Date()))
343
+ ];
344
+
345
+ nfc.write(
346
+ message,
347
+ success => console.log('wrote data to tag'),
348
+ error => console.log(error)
349
+ );
350
+
351
+ nfc.addNdefListener(onNfc);
352
+
353
+
354
+ #### iOS - Simple
355
+
356
+ Calling `nfc.write` on iOS will create a new session and write data when the user taps a NFC tag
357
+
358
+ var message = [
359
+ ndef.textRecord("Hello, world")
360
+ ];
361
+
362
+ nfc.write(
363
+ message,
364
+ success => console.log('wrote data to tag'),
365
+ error => console.log(error)
366
+ );
367
+
368
+ #### iOS - Read and Write
369
+
370
+ On iOS you can optionally write to NFC tag using the read session
371
+
372
+ try {
373
+ let tag = await nfc.scanNdef({ keepSessionOpen: true});
374
+
375
+ // you can read tag data here
376
+ console.log(tag);
377
+
378
+ // this example writes a new message with a timestamp
379
+ var message = [
380
+ ndef.textRecord(new String(new Date()))
381
+ ];
382
+
383
+ nfc.write(
384
+ message,
385
+ success => console.log('wrote data to tag'),
386
+ error => console.log(error)
387
+ );
388
+
389
+ } catch (err) {
390
+ console.log(err);
391
+ }
392
+
393
+ ### Supported Platforms
394
+
395
+ - Android
396
+ - iOS
397
+ - Windows
398
+ - BlackBerry 7
399
+ - Windows Phone 8
400
+
401
+ ## nfc.makeReadOnly
402
+
403
+ Makes a NFC tag read only. **Warning this is permanent.**
404
+
405
+ nfc.makeReadOnly([onSuccess], [onFailure]);
406
+
407
+ ### Parameters
408
+
409
+ - __onSuccess__: (Optional) The callback that is called when the tag is locked.
410
+ - __onFailure__: (Optional) The callback that is called if there was an error.
411
+
412
+ ### Description
413
+
414
+ Function `nfc.makeReadOnly` make a NFC tag read only. **Warning this is permanent** and can not be undone.
415
+
416
+ On **Android** this method *must* be called from within an NDEF Event Handler.
417
+
418
+ Example usage
419
+
420
+ onNfc: function(nfcEvent) {
421
+
422
+ var record = [
423
+ ndef.textRecord("hello, world")
424
+ ];
425
+
426
+ var failure = function(reason) {
427
+ alert("ERROR: " + reason);
428
+ };
429
+
430
+ var lockSuccess = function() {
431
+ alert("Tag is now read only.");
432
+ };
433
+
434
+ var lock = function() {
435
+ nfc.makeReadOnly(lockSuccess, failure);
436
+ };
437
+
438
+ nfc.write(record, lock, failure);
439
+
440
+ },
441
+
442
+ ### Supported Platforms
443
+
444
+ - Android
445
+
446
+ ## nfc.share
447
+
448
+ Shares an NDEF Message via peer-to-peer.
449
+
450
+ A NDEF Message is an array of one or more NDEF Records
451
+
452
+ var message = [
453
+ ndef.textRecord("hello, world")
454
+ ];
455
+
456
+ nfc.share(message, [onSuccess], [onFailure]);
457
+
458
+ ### Parameters
459
+
460
+ - __ndefMessage__: An array of NDEF Records.
461
+ - __onSuccess__: (Optional) The callback that is called when the message is pushed.
462
+ - __onFailure__: (Optional) The callback that is called if there was an error.
463
+
464
+ ### Description
465
+
466
+ Function `nfc.share` writes an NdefMessage via peer-to-peer. This should appear as an NFC tag to another device.
467
+
468
+ ### Supported Platforms
469
+
470
+ - Android
471
+ - Windows
472
+ - BlackBerry 7
473
+ - BlackBerry 10
474
+ - Windows Phone 8
475
+
476
+ ### Platform differences
477
+
478
+ Android - shares message until unshare is called
479
+ Blackberry 10 - shares the message one time or until unshare is called
480
+ Windows Phone 8 - must be called from within a NFC event handler like nfc.write
481
+
482
+ ## nfc.unshare
483
+
484
+ Stop sharing NDEF data via peer-to-peer.
485
+
486
+ nfc.unshare([onSuccess], [onFailure]);
487
+
488
+ ### Parameters
489
+
490
+ - __onSuccess__: (Optional) The callback that is called when sharing stops.
491
+ - __onFailure__: (Optional) The callback that is called if there was an error.
492
+
493
+ ### Description
494
+
495
+ Function `nfc.unshare` stops sharing data via peer-to-peer.
496
+
497
+ ### Supported Platforms
498
+
499
+ - Android
500
+ - Windows
501
+ - BlackBerry 7
502
+ - BlackBerry 10
503
+
504
+ ## nfc.erase
505
+
506
+ Erase a NDEF tag
507
+
508
+ nfc.erase([onSuccess], [onFailure]);
509
+
510
+ ### Parameters
511
+
512
+ - __onSuccess__: (Optional) The callback that is called when sharing stops.
513
+ - __onFailure__: (Optional) The callback that is called if there was an error.
514
+
515
+ ### Description
516
+
517
+ Function `nfc.erase` erases a tag by writing an empty message. Will format unformatted tags before writing.
518
+
519
+ This method *must* be called from within an NDEF Event Handler.
520
+
521
+ ### Supported Platforms
522
+
523
+ - Android
524
+ - BlackBerry 7
525
+
526
+ ## nfc.handover
527
+
528
+ Send a file to another device via NFC handover.
529
+
530
+ var uri = "content://media/external/audio/media/175";
531
+ nfc.handover(uri, [onSuccess], [onFailure]);
532
+
533
+
534
+ var uris = [
535
+ "content://media/external/audio/media/175",
536
+ "content://media/external/audio/media/176",
537
+ "content://media/external/audio/media/348"
538
+ ];
539
+ nfc.handover(uris, [onSuccess], [onFailure]);
540
+
541
+
542
+ ### Parameters
543
+
544
+ - __uri__: A URI as a String, or an *array* of URIs.
545
+ - __onSuccess__: (Optional) The callback that is called when the message is pushed.
546
+ - __onFailure__: (Optional) The callback that is called if there was an error.
547
+
548
+ ### Description
549
+
550
+ Function `nfc.handover` shares files to a NFC peer using handover. Files are sent by specifying a file:// or context:// URI or a list of URIs. The file transfer is initiated with NFC but the transfer is completed with over Bluetooth or WiFi which is handled by a NFC handover request. The Android code is responsible for building the handover NFC Message.
551
+
552
+ This is Android only, but it should be possible to add implementations for other platforms.
553
+
554
+ ### Supported Platforms
555
+
556
+ - Android
557
+
558
+ ## nfc.stopHandover
559
+
560
+ Stop sharing NDEF data via NFC handover.
561
+
562
+ nfc.stopHandover([onSuccess], [onFailure]);
563
+
564
+ ### Parameters
565
+
566
+ - __onSuccess__: (Optional) The callback that is called when sharing stops.
567
+ - __onFailure__: (Optional) The callback that is called if there was an error.
568
+
569
+ ### Description
570
+
571
+ Function `nfc.stopHandover` stops sharing data via peer-to-peer.
572
+
573
+ ### Supported Platforms
574
+
575
+ - Android
576
+
577
+ ## nfc.showSettings
578
+
579
+ Show the NFC settings on the device.
580
+
581
+ nfc.showSettings(success, failure);
582
+
583
+ ### Description
584
+
585
+ Function `showSettings` opens the NFC settings for the operating system.
586
+
587
+ ### Parameters
588
+
589
+ - __success__: Success callback function [optional]
590
+ - __failure__: Error callback function, invoked when error occurs. [optional]
591
+
592
+ ### Quick Example
593
+
594
+ nfc.showSettings();
595
+
596
+ ### Supported Platforms
597
+
598
+ - Android
599
+ - Windows
600
+ - BlackBerry 10
601
+
602
+ ## nfc.enabled
603
+
604
+ Check if NFC is available and enabled on this device.
605
+
606
+ nfc.enabled(onSuccess, onFailure);
607
+
608
+ ### Parameters
609
+
610
+ - __onSuccess__: The callback that is called when NFC is enabled.
611
+ - __onFailure__: The callback that is called when NFC is disabled or missing.
612
+
613
+ ### Description
614
+
615
+ Function `nfc.enabled` explicitly checks to see if the phone has NFC and if NFC is enabled. If
616
+ everything is OK, the success callback is called. If there is a problem, the failure callback
617
+ will be called with a reason code.
618
+
619
+ The reason will be **NO_NFC** if the device doesn't support NFC and **NFC_DISABLED** if the user has disabled NFC.
620
+
621
+ 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.
622
+
623
+ Windows will return **NO_NFC_OR_NFC_DISABLED** when NFC is not present or disabled. If the user disabled NFC after the application started, Windows may return **NFC_DISABLED**. Windows checks the NFC status before most API calls, but there are some cases when the NFC state can not be determined.
624
+
625
+ ### Supported Platforms
626
+
627
+ - Android
628
+ - iOS
629
+ - Windows
630
+
631
+ ## nfc.beginSession
632
+
633
+ **`beginSession` is deprecated. Use `scanNdef` or `scanTag`**
634
+
635
+ iOS requires you to begin a session before scanning a NFC tag.
636
+
637
+ nfc.beginSession(success, failure);
638
+
639
+ ### Description
640
+
641
+ **`beginSession` is deprecated. Use `scanNdef` or `scanTag`**
642
+
643
+ Function `beginSession` starts the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) allowing iOS to scan NFC tags. Use [nfc.addNdefListener](#nfcaddndeflistener) to receive the results of the scan.
644
+
645
+ ### Parameters
646
+
647
+ - __success__: Success callback function called when the session begins [optional]
648
+ - __failure__: Error callback function, invoked when error occurs. [optional]
649
+
650
+ ### Quick Example
651
+
652
+ nfc.beginSession();
653
+
654
+ ### Supported Platforms
655
+
656
+ - iOS
657
+
658
+ ## nfc.invalidateSession
659
+
660
+ **`invalidateSession` is deprecated. Use `cancelScan``.**
661
+
662
+ Invalidate the NFC session.
663
+
664
+ nfc.invalidateSession(success, failure);
665
+
666
+ ### Description
667
+
668
+ Function `invalidateSession` stops the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) returning control to your app.
669
+
670
+ ### Parameters
671
+
672
+ - __success__: Success callback function called when the session in invalidated [optional]
673
+ - __failure__: Error callback function, invoked when error occurs. [optional]
674
+
675
+ ### Quick Example
676
+
677
+ nfc.invalidateSession();
678
+
679
+ ### Supported Platforms
680
+
681
+ - iOS
682
+
683
+ ## nfc.scanNdef
684
+
685
+ Calling `scanNdef` will being an iOS NFC scanning session. The NFC tag will be returned in a Promise.
686
+
687
+ nfc.scanNdef();
688
+
689
+ ### Description
690
+
691
+ Function `scanNdef` starts the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) allowing iOS to scan NFC tags.
692
+
693
+ ### Returns
694
+
695
+ - Promise
696
+
697
+ ### Quick Example
698
+
699
+ // Promise
700
+ nfc.scanNdef().then(
701
+ tag => console.log(JSON.stringify(tag)),
702
+ err => console.log(err)
703
+ );
704
+
705
+ // Async Await
706
+ try {
707
+ let tag = await nfc.scanNdef();
708
+ console.log(JSON.stringify(tag));
709
+ } catch (err) {
710
+ console.log(err);
711
+ }
712
+
713
+
714
+ ### Supported Platforms
715
+
716
+ - iOS
717
+
718
+ ## nfc.scanTag
719
+
720
+ Calling `scanTag` will being an iOS NFC scanning session. The NFC tag will be returned in a Promise.
721
+
722
+ nfc.scanTag();
723
+
724
+ ### Description
725
+
726
+ Function `scanTag` starts the [NFCTagReaderSession](https://developer.apple.com/documentation/corenfc/nfctagreadersession) allowing iOS to scan NFC tags.
727
+
728
+ The Tag reader will attempt to get the UID from the NFC Tag. If can also read the UID from some non-NDEF tags.
729
+
730
+ Use [scanNdef](#nfcscanndef) for reading NFC tags on iOS unless you need to get the tag UID.
731
+
732
+ ### Returns
733
+
734
+ - Promise
735
+
736
+ ### Quick Example
737
+
738
+ // Promise
739
+ nfc.scanTag().then(
740
+ tag => {
741
+ console.log(JSON.stringify(tag))
742
+ if (tag.id) {
743
+ console.log(nfc.bytesToHexString(tag.id));
744
+ }
745
+ },
746
+ err => console.log(err)
747
+ );
748
+
749
+ // Async Await
750
+ try {
751
+ let tag = await nfc.scanTag();
752
+ console.log(JSON.stringify(tag));
753
+ if (tag.id) {
754
+ console.log(nfc.bytesToHexString(tag.id));
755
+ }
756
+ } catch (err) {
757
+ console.log(err);
758
+ }
759
+
760
+
761
+ ### Supported Platforms
762
+
763
+ - iOS
764
+
765
+
766
+ ## nfc.cancelScan
767
+
768
+ Invalidate the NFC session started by `scanNdef` or `scanTag`.
769
+
770
+ nfc.cancelScan();
771
+
772
+ ### Description
773
+
774
+ Function `cancelScan` stops the [NFCReaderSession](https://developer.apple.com/documentation/corenfc/nfcreadersession) returning control to your app.
775
+
776
+ ### Returns
777
+
778
+ - Promise
779
+
780
+ ### Quick Example
781
+
782
+ nfc.cancelScan().then(
783
+ success => { console.log('Cancelled NFC session')},
784
+ err => { console.log(`Error cancelling session ${err}`)}
785
+ );
786
+
787
+ ### Supported Platforms
788
+
789
+ - iOS
790
+
791
+
792
+ # Reader Mode Functions
793
+
794
+ ## nfc.readerMode
795
+
796
+ Read NFC tags sending the tag data to the success callback.
797
+
798
+ nfc.readerMode(flags, readCallback, errorCallback);
799
+
800
+ ### Description
801
+
802
+ In reader mode, when a NFC tags is read, the results are returned to read callback as a tag object. Note that the normal event listeners are *not* used in reader mode. The callback receives the tag object *without* the event wrapper.
803
+
804
+ {
805
+ "isWritable": true,
806
+ "id": [4, 96, 117, 74, -17, 34, -128],
807
+ "techTypes": ["android.nfc.tech.IsoDep", "android.nfc.tech.NfcA", "android.nfc.tech.Ndef"],
808
+ "type": "NFC Forum Type 4",
809
+ "canMakeReadOnly": false,
810
+ "maxSize": 2046,
811
+ "ndefMessage": [{
812
+ "id": [],
813
+ "type": [116, 101, 120, 116, 47, 112, 103],
814
+ "payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112],
815
+ "tnf": 2
816
+ }]
817
+ }
818
+
819
+ Foreground dispatching and peer-to-peer functions are disabled when reader mode is enabled.
820
+
821
+ The flags control which tags are scanned. One benefit to reader mode, is the system sounds can be disabled when a NFC tag is scanned by adding the nfc.FLAG_READER_NO_PLATFORM_SOUNDS flag. See Android's [NfcAdapter.enableReaderMode()](https://developer.android.com/reference/android/nfc/NfcAdapter#enableReaderMode(android.app.Activity,%20android.nfc.NfcAdapter.ReaderCallback,%20int,%20android.os.Bundle)) documentation for more info on the flags.
822
+
823
+
824
+ ### Parameters
825
+
826
+ - __flags__: Flags indicating poll technologies and other optional parameters
827
+ - __readCallback__: The callback that is called when a NFC tag is scanned.
828
+ - __errorCallback__: The callback that is called when NFC is disabled or missing.
829
+
830
+ ### Quick Example
831
+
832
+ nfc.readerMode(
833
+ nfc.FLAG_READER_NFC_A | nfc.FLAG_READER_NO_PLATFORM_SOUNDS,
834
+ nfcTag => console.log(JSON.stringify(nfcTag)),
835
+ error => console.log('NFC reader mode failed', error)
836
+ );
837
+
838
+ ### Supported Platforms
839
+
840
+ - Android
841
+
842
+ ## nfc.disableReaderMode
843
+
844
+ Disable NFC reader mode.
845
+
846
+ nfc.disableNfcReaderMode(successCallback, errorCallback);
847
+
848
+ ### Description
849
+
850
+ Disable NFC reader mode.
851
+
852
+ ### Parameters
853
+
854
+ - __successCallback__: The callback that is called when a NFC reader mode is disabled.
855
+ - __errorCallback__: The callback that is called when NFC reader mode can not be disabled.
856
+
857
+ ### Quick Example
858
+
859
+ nfc.disableReaderMode(
860
+ () => console.log('NFC reader mode disabled'),
861
+ error => console.log('Error disabling NFC reader mode', error)
862
+ )
863
+
864
+ ### Supported Platforms
865
+
866
+ - Android
867
+
868
+
869
+ # Tag Technology Functions
870
+
871
+ The tag technology functions provide access to I/O operations on a tag. Connect to a tag, send commands with transceive, close the tag. See the [Android TagTechnology](https://developer.android.com/reference/android/nfc/tech/TagTechnology) and implementations like [IsoDep](https://developer.android.com/reference/android/nfc/tech/IsoDep) and [NfcV](https://developer.android.com/reference/android/nfc/tech/NfcV) for more details. These new APIs are promise based rather than using callbacks.
872
+
873
+ #### ISO-DEP (ISO 14443-4) Example
874
+
875
+ const DESFIRE_SELECT_PICC = '00 A4 04 00 07 D2 76 00 00 85 01 00';
876
+ const DESFIRE_SELECT_AID = '90 5A 00 00 03 AA AA AA 00'
877
+
878
+ async function handleDesfire(nfcEvent) {
879
+
880
+ const tagId = nfc.bytesToHexString(nfcEvent.tag.id);
881
+ console.log('Processing', tagId);
882
+
883
+ try {
884
+ await nfc.connect('android.nfc.tech.IsoDep', 500);
885
+ console.log('connected to', tagId);
886
+
887
+ let response = await nfc.transceive(DESFIRE_SELECT_PICC);
888
+ ensureResponseIs('9000', response);
889
+
890
+ response = await nfc.transceive(DESFIRE_SELECT_AID);
891
+ ensureResponseIs('9100', response);
892
+ // 91a0 means the requested application not found
893
+
894
+ alert('Selected application AA AA AA');
895
+
896
+ // more transcieve commands go here
897
+
898
+ } catch (error) {
899
+ alert(error);
900
+ } finally {
901
+ await nfc.close();
902
+ console.log('closed');
903
+ }
904
+
905
+ }
906
+
907
+ function ensureResponseIs(expectedResponse, buffer) {
908
+ const responseString = util.arrayBufferToHexString(buffer);
909
+ if (expectedResponse !== responseString) {
910
+ const error = 'Expecting ' + expectedResponse + ' but received ' + responseString;
911
+ throw error;
912
+ }
913
+ }
914
+
915
+ function onDeviceReady() {
916
+ nfc.addTagDiscoveredListener(handleDesfire);
917
+ }
918
+
919
+ document.addEventListener('deviceready', onDeviceReady, false);
920
+
921
+ ## nfc.connect
922
+
923
+ Connect to the tag and enable I/O operations to the tag from this TagTechnology object.
924
+
925
+ nfc.connect(tech);
926
+
927
+ nfc.connect(tech, timeout);
928
+
929
+ ### Description
930
+
931
+ Function `connect` enables I/O operations to the tag from this TagTechnology object. `nfc.connect` should be called after receiving a nfcEvent from the `addTagDiscoveredListener` or the `readerMode` callback. Only one TagTechnology object can be connected to a Tag at a time.
932
+
933
+ See Android's [TagTechnology.connect()](https://developer.android.com/reference/android/nfc/tech/TagTechnology.html#connect()) for more info.
934
+
935
+ ### Parameters
936
+
937
+ - __tech__: The tag technology e.g. android.nfc.tech.IsoDep
938
+ - __timeout__: The transceive(byte[]) timeout in milliseconds [optional]
939
+
940
+ ### Returns
941
+
942
+ - Promise when the connection is successful, optionally with a maxTransceiveLength attribute in case the tag technology supports it
943
+
944
+ ### Quick Example
945
+
946
+ nfc.addTagDiscoveredListener(function(nfcEvent) {
947
+ nfc.connect('android.nfc.tech.IsoDep', 500).then(
948
+ () => console.log('connected to', nfc.bytesToHexString(nfcEvent.tag.id)),
949
+ (error) => console.log('connection failed', error)
950
+ );
951
+ })
952
+
953
+ ### Supported Platforms
954
+
955
+ - Android
956
+
957
+ ## nfc.transceive
958
+
959
+ Send raw command to the tag and receive the response.
960
+
961
+ nfc.transceive(data);
962
+
963
+ ### Description
964
+
965
+ 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.
966
+
967
+ 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.
968
+
969
+ ### Parameters
970
+
971
+ - __data__: a string of hex data or an ArrayBuffer
972
+
973
+ ### Returns
974
+
975
+ - Promise with the response data as an ArrayBuffer
976
+
977
+ ### Quick Example
978
+
979
+ // Promise style
980
+ nfc.transceive('90 5A 00 00 03 AA AA AA 00').then(
981
+ response => console.log(util.arrayBufferToHexString(response)),
982
+ error => console.log('Error selecting DESFire application')
983
+ )
984
+
985
+ // async await
986
+ const response = await nfc.transceive('90 5A 00 00 03 AA AA AA 00');
987
+ console.log('response =',util.arrayBufferToHexString(response));
988
+
989
+ ### Supported Platforms
990
+
991
+ - Android
992
+
993
+ ## nfc.close
994
+
995
+ Close TagTechnology connection.
996
+
997
+ nfc.close();
998
+
999
+ ### Description
1000
+
1001
+ Function `close` disabled I/O operations to the tag from this TagTechnology object, and releases resources.
1002
+
1003
+ See Android's [TagTechnology.close()](https://developer.android.com/reference/android/nfc/tech/TagTechnology.html#close()) for more info.
1004
+
1005
+ ### Parameters
1006
+
1007
+ - none
1008
+
1009
+ ### Returns
1010
+
1011
+ - Promise when the connection is successfully closed
1012
+
1013
+ ### Quick Example
1014
+
1015
+ nfc.transceive().then(
1016
+ () => console.log('connection closed'),
1017
+ (error) => console.log('error closing connection', error);
1018
+ )
1019
+
1020
+ ### Supported Platforms
1021
+
1022
+ - Android
1023
+
1024
+ # NDEF
1025
+
1026
+ > The `ndef` object provides NDEF constants, functions for creating NdefRecords, and functions for converting data.
1027
+ > See [android.nfc.NdefRecord](http://developer.android.com/reference/android/nfc/NdefRecord.html) for documentation about constants
1028
+
1029
+ ## NdefMessage
1030
+
1031
+ Represents an NDEF (NFC Data Exchange Format) data message that contains one or more NdefRecords.
1032
+ This plugin uses an array of NdefRecords to represent an NdefMessage.
1033
+
1034
+ ## NdefRecord
1035
+
1036
+ Represents a logical (unchunked) NDEF (NFC Data Exchange Format) record.
1037
+
1038
+ ### Properties
1039
+
1040
+ - __tnf__: 3-bit TNF (Type Name Format) - use one of the TNF_* constants
1041
+ - __type__: byte array, containing zero to 255 bytes, must not be null
1042
+ - __id__: byte array, containing zero to 255 bytes, must not be null
1043
+ - __payload__: byte array, containing zero to (2 ** 32 - 1) bytes, must not be null
1044
+
1045
+ The `ndef` object has a function for creating NdefRecords
1046
+
1047
+ var type = "text/pg",
1048
+ id = [],
1049
+ payload = nfc.stringToBytes("Hello World"),
1050
+ record = ndef.record(ndef.TNF_MIME_MEDIA, type, id, payload);
1051
+
1052
+ There are also helper functions for some types of records
1053
+
1054
+ Create a URI record
1055
+
1056
+ var record = ndef.uriRecord("http://chariotsolutions.com");
1057
+
1058
+ Create a plain text record
1059
+
1060
+ var record = ndef.textRecord("Plain text message");
1061
+
1062
+ Create a mime type record
1063
+
1064
+ var mimeType = "text/pg",
1065
+ payload = "Hello Phongap",
1066
+ record = ndef.mimeMediaRecord(mimeType, nfc.stringToBytes(payload));
1067
+
1068
+ Create an Empty record
1069
+
1070
+ var record = ndef.emptyRecord();
1071
+
1072
+ Create an Android Application Record (AAR)
1073
+
1074
+ var record = ndef.androidApplicationRecord('com.example');
1075
+
1076
+ See `ndef.record`, `ndef.textRecord`, `ndef.mimeMediaRecord`, and `ndef.uriRecord`.
1077
+
1078
+ The Ndef object has functions to convert some data types to and from byte arrays.
1079
+
1080
+ See the [phonegap-nfc.js](https://github.com/chariotsolutions/phonegap-nfc/blob/master/www/phonegap-nfc.js) source for more documentation.
1081
+
1082
+ # Events
1083
+
1084
+ 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);`
1085
+
1086
+ ## NfcEvent
1087
+
1088
+ ### Properties
1089
+
1090
+ - __type__: event type
1091
+ - __tag__: Ndef tag
1092
+
1093
+ ### Types
1094
+
1095
+ - tag
1096
+ - ndef-mime
1097
+ - ndef
1098
+ - ndef-formatable
1099
+
1100
+ The tag contents are platform dependent.
1101
+
1102
+ `id` and `techTypes` may be included when scanning a tag on Android. `serialNumber` may be included on BlackBerry 7.
1103
+
1104
+ `id` and `serialNumber` are different names for the same value. `id` is typically displayed as a hex string `nfc.bytesToHexString(tag.id)`.
1105
+
1106
+ Windows, Windows Phone 8, and BlackBerry 10 read the NDEF information from a tag, but do not have access to the tag id or other meta data like capacity, read-only status or tag technologies.
1107
+
1108
+ Assuming the following NDEF message is written to a tag, it will produce the following events when read.
1109
+
1110
+ var ndefMessage = [
1111
+ ndef.createMimeRecord('text/pg', 'Hello PhoneGap')
1112
+ ];
1113
+
1114
+ #### Sample Event on Android
1115
+
1116
+ {
1117
+ type: 'ndef',
1118
+ tag: {
1119
+ "isWritable": true,
1120
+ "id": [4, 96, 117, 74, -17, 34, -128],
1121
+ "techTypes": ["android.nfc.tech.IsoDep", "android.nfc.tech.NfcA", "android.nfc.tech.Ndef"],
1122
+ "type": "NFC Forum Type 4",
1123
+ "canMakeReadOnly": false,
1124
+ "maxSize": 2046,
1125
+ "ndefMessage": [{
1126
+ "id": [],
1127
+ "type": [116, 101, 120, 116, 47, 112, 103],
1128
+ "payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112],
1129
+ "tnf": 2
1130
+ }]
1131
+ }
1132
+ }
1133
+
1134
+ #### Sample Event on BlackBerry 7
1135
+
1136
+ {
1137
+ type: 'ndef',
1138
+ tag: {
1139
+ "tagType": "4",
1140
+ "isLocked": false,
1141
+ "isLockable": false,
1142
+ "freeSpaceSize": "2022",
1143
+ "serialNumberLength": "7",
1144
+ "serialNumber": [4, 96, 117, 74, -17, 34, -128],
1145
+ "name": "Desfire EV1 2K",
1146
+ "ndefMessage": [{
1147
+ "tnf": 2,
1148
+ "type": [116, 101, 120, 116, 47, 112, 103],
1149
+ "id": [],
1150
+ "payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112]
1151
+ }]
1152
+ }
1153
+ }
1154
+
1155
+ #### Sample Event on Windows, BlackBerry 10, or Windows Phone 8
1156
+
1157
+ {
1158
+ type: 'ndef',
1159
+ tag: {
1160
+ "ndefMessage": [{
1161
+ "tnf": 2,
1162
+ "type": [116, 101, 120, 116, 47, 112, 103],
1163
+ "id": [],
1164
+ "payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112]
1165
+ }]
1166
+ }
1167
+ }
1168
+
1169
+ ## Getting Details about Events
1170
+
1171
+ The raw contents of the scanned tags are written to the log before the event is fired. Use `adb logcat` on Android and Event Log (hold alt + lglg) on BlackBerry.
1172
+
1173
+ 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.
1174
+
1175
+ # Platform Differences
1176
+
1177
+ ## Non-NDEF Tags
1178
+
1179
+ Only Android and BlackBerry 7 can read data from non-NDEF NFC tags. Newer Windows Phones with NXP PN427 chipset can read non-NDEF tags, but can not get any tag meta data.
1180
+
1181
+ ## Mifare Classic Tags
1182
+
1183
+ BlackBerry 7, BlackBerry 10 and many newer Android phones will not read Mifare Classic tags. Mifare Ultralight tags will work since they are NFC Forum Type 2 tags. Newer Windows 8.1 phones (Lumia 640) can read Mifare Classic tags.
1184
+
1185
+ ## Tag Id and Meta Data
1186
+
1187
+ Windows Phone 8, BlackBerry 10, and Windows read the NDEF information from a tag, but do not have access to the tag id or other meta data like capacity, read-only status or tag technologies.
1188
+
1189
+ ## Multiple Listeners
1190
+
1191
+ Multiple listeners can be registered in JavaScript. e.g. addNdefListener, addTagDiscoveredListener, addMimeTypeListener.
1192
+
1193
+ 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.
1194
+
1195
+ For Windows, this plugin mimics the Android behavior. If an ndef event is fired, a tag event will not be fired. You should receive one event per tag.
1196
+
1197
+ On BlackBerry 7, all the events fire if a Mime Media Tag is scanned.
1198
+
1199
+ ## addTagDiscoveredListener
1200
+
1201
+ On Android, addTagDiscoveredListener scans non-NDEF tags and NDEF tags. The tag event does NOT contain an ndefMessage even if there are NDEF messages on the tag. Use addNdefListener or addMimeTypeListener to get the NDEF information.
1202
+
1203
+ Windows can scan non-NDEF (unformatted) tags using addTagDiscoveredListener. The tag event will not include any data.
1204
+
1205
+ On BlackBerry 7, addTagDiscoveredListener does NOT scan non-NDEF tags. Webworks returns the ndefMessage in the event.
1206
+
1207
+ ### Non-NDEF tag scanned with addTagDiscoveredListener on *Android*
1208
+
1209
+ {
1210
+ type: 'tag',
1211
+ tag: {
1212
+ "id": [-81, 105, -4, 64],
1213
+ "techTypes": ["android.nfc.tech.MifareClassic", "android.nfc.tech.NfcA", "android.nfc.tech.NdefFormatable"]
1214
+ }
1215
+ }
1216
+
1217
+
1218
+ ### NDEF tag scanned with addTagDiscoveredListener on *Android*
1219
+
1220
+ {
1221
+ type: 'tag',
1222
+ tag: {
1223
+ "id": [4, 96, 117, 74, -17, 34, -128],
1224
+ "techTypes": ["android.nfc.tech.IsoDep", "android.nfc.tech.NfcA", "android.nfc.tech.Ndef"]
1225
+ }
1226
+ }
1227
+
1228
+ ### Non-NDEF tag scanned with addTagDiscoveredListener on *Windows*
1229
+
1230
+ {
1231
+ type: 'tag',
1232
+ tag: {
1233
+ }
1234
+ }
1235
+
1236
+ # BlackBerry 10 Invoke Target
1237
+
1238
+ This plugin uses the [BlackBerry Invocation Framework](http://developer.blackberry.com/native/documentation/cascades/device_platform/invocation/receiving_invocation.html) to read NFC tags on BlackBerry 10. This means that you need to register an invoke target in the config.xml.
1239
+
1240
+ If your project supports multiple platforms, copy www/config.xml to merges/config.xml and add a `rim:invoke-target` tag. The invoke-target determines which tags your app will scan when it is running. If your application is not running, BlackBerry will launch it when a matching tag is scanned.
1241
+
1242
+ This sample configuration attempts to open any NDEF tag.
1243
+
1244
+ <rim:invoke-target id="your.unique.id.here">
1245
+ <type>APPLICATION</type>
1246
+ <filter>
1247
+ <action>bb.action.OPEN</action>
1248
+ <mime-type>application/vnd.rim.nfc.ndef</mime-type>
1249
+ <!-- any TNF Empty(0), Well Known(1), MIME Media(2), Absolute URI(3), External(4) -->
1250
+ <property var="uris" value="ndef://0,ndef://1,ndef://2,ndef://3,ndef://4" />
1251
+ </filter>
1252
+ </rim:invoke-target>
1253
+
1254
+ You can configure you application to handle only certain tags.
1255
+
1256
+ For example to scan only MIME Media tags of type "text/pg" use
1257
+
1258
+ <rim:invoke-target id="your.unique.id.here">
1259
+ <type>APPLICATION</type>
1260
+ <filter>
1261
+ <action>bb.action.OPEN</action>
1262
+ <mime-type>application/vnd.rim.nfc.ndef</mime-type>
1263
+ <!-- TNF MIME Media(2) with type "text/pg" -->
1264
+ <property var="uris" value="ndef://2/text/pg" />
1265
+ </filter>
1266
+ </rim:invoke-target>
1267
+
1268
+ Or to scan only Plain Text tags use
1269
+
1270
+ <rim:invoke-target id="your.unique.id.here">
1271
+ <type>APPLICATION</type>
1272
+ <filter>
1273
+ <action>bb.action.OPEN</action>
1274
+ <mime-type>application/vnd.rim.nfc.ndef</mime-type>
1275
+ <!-- TNF Well Known(1), RTD T -->
1276
+ <property var="uris" value="ndef://1/T" />
1277
+ </filter>
1278
+ </rim:invoke-target>
1279
+
1280
+ See the [BlackBerry documentation](http://developer.blackberry.com/native/documentation/cascades/device_comm/nfc/receiving_content.html) for more info.
1281
+
1282
+ # Launching your Android Application when Scanning a Tag
1283
+
1284
+ On Android, intents can be used to launch your application when a NFC tag is read. This is optional and configured in AndroidManifest.xml.
1285
+
1286
+ <intent-filter>
1287
+ <action android:name="android.nfc.action.NDEF_DISCOVERED" />
1288
+ <data android:mimeType="text/pg" />
1289
+ <category android:name="android.intent.category.DEFAULT" />
1290
+ </intent-filter>
1291
+
1292
+ Note: `data android:mimeType="text/pg"` should match the data type you specified in JavaScript
1293
+
1294
+ 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.
1295
+
1296
+ See the Android documentation for more information about [filtering for NFC intents](http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#ndef-disc).
1297
+
1298
+ Testing
1299
+ =======
1300
+
1301
+ Tests require the [Cordova Plugin Test Framework](https://github.com/apache/cordova-plugin-test-framework)
1302
+
1303
+ Create a new project
1304
+
1305
+ git clone https://github.com/chariotsolutions/phonegap-nfc
1306
+ cordova create nfc-test com.example.nfc.test NfcTest
1307
+ cd nfc-test
1308
+ cordova platform add android
1309
+ cordova plugin add ../phonegap-nfc
1310
+ cordova plugin add ../phonegap-nfc/tests
1311
+ cordova plugin add https://github.com/apache/cordova-plugin-test-framework.git
1312
+
1313
+ Change the start page in `config.xml`
1314
+
1315
+ <content src="cdvtests/index.html" />
1316
+
1317
+ Run the app on your phone
1318
+
1319
+ cordova run
1320
+
1321
+
1322
+ Sample Projects
1323
+ ================
1324
+
1325
+ - [Ionic NFC Reader](https://github.com/don/ionic-nfc-reader)
1326
+ - [NFC Reader](https://github.com/don/phonegap-nfc-reader)
1327
+ - [NFC Writer](https://github.com/don/phonegap-nfc-writer)
1328
+ - [NFC Peer to Peer](https://github.com/don/phonegap-p2p)
1329
+ - [ApacheCon 2014 Demos](https://github.com/don/apachecon-nfc-demos)
1330
+ - [Rock Paper Scissors](https://github.com/don/rockpaperscissors) *Android 2.x only*
1331
+
1332
+ HCE
1333
+ =======
1334
+
1335
+ For Host Card Emulation (HCE), try the [Cordova HCE Plugin](https://github.com/don/cordova-plugin-hce).
1336
+
1337
+ Book
1338
+ =======
1339
+ Need more info? Check out my book <a href="http://www.tkqlhce.com/click-7835726-11260198-1430755877000?url=http%3A%2F%2Fshop.oreilly.com%2Fproduct%2F0636920021193.do%3Fcmp%3Daf-prog-books-videos-product_cj_9781449372064_%2525zp&cjsku=0636920021193" target="_top">
1340
+ Beginning NFC: Near Field Communication with Arduino, Android, and PhoneGap</a><img src="http://www.lduhtrp.net/image-7835726-11260198-1430755877000" width="1" height="1" border="0"/>
1341
+
1342
+ <a href="http://www.kqzyfj.com/click-7835726-11260198-1430755877000?url=http%3A%2F%2Fshop.oreilly.com%2Fproduct%2F0636920021193.do%3Fcmp%3Daf-prog-books-videos-product_cj_9781449372064_%2525zp&cjsku=0636920021193" target="_top"><img src="http://akamaicovers.oreilly.com/images/0636920021193/cat.gif" border="0" alt="Beginning NFC"/></a><img src="http://www.ftjcfx.com/image-7835726-11260198-1430755877000" width="1" height="1" border="0"/>
1343
+
1344
+ License
1345
+ ================
1346
+
1347
+ The MIT License
1348
+
1349
+ Copyright (c) 2011-2020 Chariot Solutions
1350
+
1351
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1352
+ of this software and associated documentation files (the "Software"), to deal
1353
+ in the Software without restriction, including without limitation the rights
1354
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1355
+ copies of the Software, and to permit persons to whom the Software is
1356
+ furnished to do so, subject to the following conditions:
1357
+
1358
+ The above copyright notice and this permission notice shall be included in
1359
+ all copies or substantial portions of the Software.
1360
+
1361
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1362
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1363
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1364
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1365
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1366
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1367
+ THE SOFTWARE.
1368
+
1369
+ [w3c_spec]: https://www.w3.org/TR/battery-status/
1370
+ [status_object]: #status-object
1371
+ [community_plugins]: https://github.com/EYALIN?tab=repositories&q=community&type=&language=&sort=