phonegap-nfc
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,5 @@ | ||
= 1.0.2 = | ||
Add reader mode for Android #326 #198 | ||
Add es6 to jshint config, remove strict mode, cleanup jshint errors #325 | ||
= 1.0.1 = | ||
@@ -2,0 +6,0 @@ Replace webview.sendJavascript with channel on Android Fixes #196 #249 #225 #263 Thanks jmorille |
{ | ||
"name": "phonegap-nfc", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Near Field Communication (NFC) Plugin. Read and write NDEF messages to NFC tags and share NDEF messages with peers.", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -96,2 +96,7 @@ PhoneGap NFC Plugin | ||
## ReaderMode | ||
- [nfc.readerMode](#nfcreadermode) | ||
- [nfc.disableReaderMode](#nfcdisablereadermode) | ||
## Tag Technology Functions | ||
@@ -588,2 +593,79 @@ | ||
# Reader Mode Functions | ||
## nfc.readerMode | ||
Read NFC tags sending the tag data to the success callback. | ||
nfc.readerMode(flags, readCallback, errorCallback); | ||
### Description | ||
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. | ||
{ | ||
"isWritable": true, | ||
"id": [4, 96, 117, 74, -17, 34, -128], | ||
"techTypes": ["android.nfc.tech.IsoDep", "android.nfc.tech.NfcA", "android.nfc.tech.Ndef"], | ||
"type": "NFC Forum Type 4", | ||
"canMakeReadOnly": false, | ||
"maxSize": 2046, | ||
"ndefMessage": [{ | ||
"id": [], | ||
"type": [116, 101, 120, 116, 47, 112, 103], | ||
"payload": [72, 101, 108, 108, 111, 32, 80, 104, 111, 110, 101, 71, 97, 112], | ||
"tnf": 2 | ||
}] | ||
} | ||
Foreground dispatching and peer-to-peer functions are disabled when reader mode is enabled. | ||
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. | ||
### Parameters | ||
- __flags__: Flags indicating poll technologies and other optional parameters | ||
- __readCallback__: The callback that is called when a NFC tag is scanned. | ||
- __errorCallback__: The callback that is called when NFC is disabled or missing. | ||
### Quick Example | ||
nfc.readerMode( | ||
nfc.FLAG_READER_NFC_A | nfc.FLAG_READER_NO_PLATFORM_SOUNDS, | ||
nfcTag => console.log(JSON.stringify(nfcTag)), | ||
error => console.log('NFC reader mode failed', error) | ||
); | ||
### Supported Platforms | ||
- Android | ||
## nfc.disableReaderMode | ||
Disable NFC reader mode. | ||
nfc.disableNfcReaderMode(successCallback, errorCallback); | ||
### Description | ||
Disable NFC reader mode. | ||
### Parameters | ||
- __successCallback__: The callback that is called when a NFC reader mode is disabled. | ||
- __errorCallback__: The callback that is called when NFC reader mode can not be disabled. | ||
### Quick Example | ||
nfc.disableReaderMode( | ||
() => console.log('NFC reader mode disabled'), | ||
error => console.log('Error disabling NFC reader mode', error) | ||
) | ||
### Supported Platforms | ||
- Android | ||
# Tag Technology Functions | ||
@@ -590,0 +672,0 @@ |
@@ -1,4 +0,3 @@ | ||
/*jshint bitwise: false, camelcase: false, quotmark: false, unused: vars */ | ||
/*global cordova, console */ | ||
"use strict"; | ||
/*jshint bitwise: false, camelcase: false, quotmark: false, unused: vars, esversion: 6, browser: true*/ | ||
/*global cordova, console, require */ | ||
@@ -274,5 +273,5 @@ function handleNfcFromIntentFilter() { | ||
*/ | ||
decodeMessage: function (bytes) { | ||
decodeMessage: function (ndefBytes) { | ||
var bytes = bytes.slice(0), // clone since parsing is destructive | ||
var bytes = ndefBytes.slice(0), // clone since parsing is destructive | ||
ndef_message = [], | ||
@@ -415,3 +414,3 @@ tnf_byte, | ||
var nfc = { | ||
addTagDiscoveredListener: function (callback, win, fail) { | ||
@@ -532,2 +531,20 @@ document.addEventListener("tag", callback, false); | ||
}); | ||
}, | ||
// Android NfcAdapter.enableReaderMode flags | ||
FLAG_READER_NFC_A: 0x1, | ||
FLAG_READER_NFC_B: 0x2, | ||
FLAG_READER_NFC_F: 0x4, | ||
FLAG_READER_NFC_V: 0x8, | ||
FLAG_READER_NFC_BARCODE: 0x10, | ||
FLAG_READER_SKIP_NDEF_CHECK: 0x80, | ||
FLAG_READER_NO_PLATFORM_SOUNDS: 0x100, | ||
// Android NfcAdapter.enabledReaderMode | ||
readerMode: function(flags, readCallback, errorCallback) { | ||
cordova.exec(readCallback, errorCallback, 'NfcPlugin', 'readerMode', [flags]); | ||
}, | ||
disableReaderMode: function(successCallback, errorCallback) { | ||
cordova.exec(successCallback, errorCallback, 'NfcPlugin', 'disableReaderMode', []); | ||
} | ||
@@ -745,3 +762,8 @@ | ||
// TODO need to deal with UTF in the future | ||
// console.log("lang " + languageCode + (utf16 ? " utf16" : " utf8")); | ||
if (utf16) { | ||
console.log('WARNING: utf-16 data may not be handled properly for', languageCode); | ||
} | ||
// Use TextDecoder when we have enough browser support | ||
// new TextDecoder('utf-8').decode(data.slice(languageCodeLength + 1)); | ||
// new TextDecoder('utf-16').decode(data.slice(languageCodeLength + 1)); | ||
@@ -850,3 +872,3 @@ return util.bytesToString(data.slice(languageCodeLength + 1)); | ||
var e = document.createEvent('Events'); | ||
e.initEvent(message.type) | ||
e.initEvent(message.type); | ||
e.tag = message.tag; | ||
@@ -853,0 +875,0 @@ document.dispatchEvent(e); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
411756
1204
1168