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.
@@ -0,0 +1,64 @@
1
+ # Getting Started with PhoneGap NFC on BlackBerry 10
2
+
3
+ Hardware & Software
4
+ * OSX 10.10.5
5
+ * BB10 WebWorks SDK 2.2.0.15
6
+ * Cordova 5.5.3
7
+ * PhoneGap NFC 0.6.5
8
+ * BlackBerry Z10 running 10.3.1.156
9
+
10
+ Create the project and install the plugins
11
+
12
+ cordova create nfc com.example.nfc HelloNFC
13
+ cd nfc
14
+ cordova platform add blackberry10
15
+ cordova plugin add phonegap-nfc
16
+ cordova plugin add cordova-plugin-bb-invoke
17
+
18
+ edit `www/js/index.js` and replace `onDeviceReady` with
19
+
20
+ onDeviceReady: function() {
21
+ app.receivedEvent('deviceready');
22
+
23
+ // Read NDEF formatted NFC Tags
24
+ nfc.addNdefListener (
25
+ function (nfcEvent) {
26
+ var tag = nfcEvent.tag,
27
+ ndefMessage = tag.ndefMessage;
28
+
29
+ // dump the raw json of the message
30
+ // note: real code will need to decode
31
+ // the payload from each record
32
+ alert(JSON.stringify(ndefMessage));
33
+
34
+ // assuming the first record in the message has
35
+ // a payload that can be converted to a string.
36
+ alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
37
+ },
38
+ function () { // success callback
39
+ alert("Waiting for NDEF tag");
40
+ },
41
+ function (error) { // error callback
42
+ alert("Error adding NDEF listener " + JSON.stringify(error));
43
+ }
44
+ );
45
+ },
46
+
47
+ Edit `config.xml` and `<rim:invoke-target>` just before `</widget>`. (See docs for more info about [invoke-target](https://github.com/chariotsolutions/phonegap-nfc#blackberry-10-invoke-target
48
+ ).)
49
+
50
+ <rim:invoke-target id="your.unique.id.here">
51
+ <type>APPLICATION</type>
52
+ <filter>
53
+ <action>bb.action.OPEN</action>
54
+ <mime-type>application/vnd.rim.nfc.ndef</mime-type>
55
+ <!-- any TNF Empty(0), Well Known(1), MIME Media(2), Absolute URI(3), External(4) -->
56
+ <property var="uris" value="ndef://0,ndef://1,ndef://2,ndef://3,ndef://4" />
57
+ </filter>
58
+ </rim:invoke-target>
59
+
60
+ Compile, install, and run
61
+
62
+ cordova run
63
+
64
+ ![bb10-nfc](https://cloud.githubusercontent.com/assets/3133/10735553/014668f4-7bdf-11e5-9fc3-7d5a8eb95087.png)
@@ -0,0 +1,71 @@
1
+ ## Quickstart for PhoneGap NFC - Cordova CLI
2
+
3
+ These instructions use [Cordova](http://cordova.apache.org/) to generate a default PhoneGap app and modify it to read NFC tags. BlackBerry users should refer to [Getting Started with BlackBerry 10](https://github.com/chariotsolutions/phonegap-nfc/blob/master/doc/GettingStartedBlackBerry10.md).
4
+
5
+ ### Cordova Command Line Interface (CLI)
6
+
7
+ The Cordova Command Line Interface [cordova-cli](https://npmjs.org/package/cordova) can be used to create, build and run multi-platform Cordova projects. Cordova CLI requires [node.js](http://nodejs.org), [git](http://git-scm.com/) and the SDK tools for your target platform (Android, BlackBerry10 or Windows Phone 8.)
8
+
9
+ $ npm install cordova -g
10
+
11
+ ### Generate a project
12
+
13
+ $ cd ~
14
+ $ cordova create foo com.example.foo Foo
15
+
16
+ ### Add Android
17
+
18
+ $ cd foo
19
+ $ cordova platform add android
20
+
21
+ ### Install the Plugin
22
+
23
+ $ cordova plugin add phonegap-nfc
24
+
25
+ ### Edit `index.js`
26
+
27
+ Edit `index.js` and modify onDeviceReady with the following code
28
+
29
+ onDeviceReady: function() {
30
+ app.receivedEvent('deviceready');
31
+
32
+ // Read NDEF formatted NFC Tags
33
+ nfc.addNdefListener (
34
+ function (nfcEvent) {
35
+ var tag = nfcEvent.tag,
36
+ ndefMessage = tag.ndefMessage;
37
+
38
+ // dump the raw json of the message
39
+ // note: real code will need to decode
40
+ // the payload from each record
41
+ alert(JSON.stringify(ndefMessage));
42
+
43
+ // assuming the first record in the message has
44
+ // a payload that can be converted to a string.
45
+ alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
46
+ },
47
+ function () { // success callback
48
+ alert("Waiting for NDEF tag");
49
+ },
50
+ function (error) { // error callback
51
+ alert("Error adding NDEF listener " + JSON.stringify(error));
52
+ }
53
+ );
54
+ },
55
+
56
+ ### Run the code
57
+
58
+ Plug your phone into your computer.
59
+
60
+ Build and run the code
61
+
62
+ $ cd ~/foo
63
+ $ cordova run
64
+
65
+ ### Scan a NDEF tag
66
+
67
+ Scan an NDEF tag with your phone. If you need to put data on a tag, try writing a plain text message to a tag with [NXP Tag Writer](https://play.google.com/store/apps/details?id=com.nxp.nfc.tagwriter).
68
+
69
+ ![Basic App](read_tag_1_basic_app.png "Basic App")
70
+ ![Dump Tag As JSON](read_tag_2_dump_tag.png "Dump Tag As JSON")
71
+ ![Payload As String](read_tag_3_payload_as_string.png "Payload As String")
@@ -0,0 +1,77 @@
1
+ ## Quickstart for PhoneGap NFC with PhoneGap Build
2
+
3
+ These instructions use [PhoneGap](http://phonegap.com/) to generate a default PhoneGap app, modify it to read NFC tags and build using [PhoneGap Build](http://build.phonegap.com).
4
+
5
+ ### PhoneGap Command Line Interface (CLI)
6
+
7
+ The PhoneGap Command Line Interface [phonegap-cli](https://npmjs.org/package/phonegap) can be used to create, build and run multi-platform PhoneGap projects. PhoneGap CLI requires [node.js](http://nodejs.org).
8
+
9
+ $ npm install phonegap -g
10
+
11
+ ### Generate a project
12
+
13
+ $ cd ~
14
+ $ phonegap create nfc com.example.nfc NFC
15
+
16
+ ### Install the Plugin
17
+
18
+ Change to the project directory
19
+
20
+ $ cd nfc
21
+
22
+ Edit `config.xml` and add a line to install the plugin
23
+
24
+ <gap:plugin name="phonegap-nfc" source="npm" />
25
+
26
+ ### Edit `index.js`
27
+
28
+ Edit `index.js` and modify onDeviceReady with the following code
29
+
30
+ onDeviceReady: function() {
31
+ app.receivedEvent('deviceready');
32
+
33
+ // Read NDEF formatted NFC Tags
34
+ nfc.addNdefListener (
35
+ function (nfcEvent) {
36
+ var tag = nfcEvent.tag,
37
+ ndefMessage = tag.ndefMessage;
38
+
39
+ // dump the raw json of the message
40
+ // note: real code will need to decode
41
+ // the payload from each record
42
+ alert(JSON.stringify(ndefMessage));
43
+
44
+ // assuming the first record in the message has
45
+ // a payload that can be converted to a string.
46
+ alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
47
+ },
48
+ function () { // success callback
49
+ alert("Waiting for NDEF tag");
50
+ },
51
+ function (error) { // error callback
52
+ alert("Error adding NDEF listener " + JSON.stringify(error));
53
+ }
54
+ );
55
+ },
56
+
57
+ ### Build the code using PhoneGap Build's servers
58
+
59
+ $ phonegap remote build android
60
+
61
+ ### Install the app from the PhoneGap Build website
62
+
63
+ Log into http://build.phonegap.com with your phone.
64
+
65
+ ![PhoneGap Build](phonegap_build.png "PhoneGap Build")
66
+
67
+ Download and install the app.
68
+
69
+ Run the app.
70
+
71
+ ### Scan a NDEF tag
72
+
73
+ Scan an NDEF tag with your phone. If you need to put data on a tag, try writing a plain text message to a tag with [NXP Tag Writer](https://play.google.com/store/apps/details?id=com.nxp.nfc.tagwriter).
74
+
75
+ ![Basic App](read_tag_1_basic_app.png "Basic App")
76
+ ![Dump Tag As JSON](read_tag_2_dump_tag.png "Dump Tag As JSON")
77
+ ![Payload As String](read_tag_3_payload_as_string.png "Payload As String")
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "community-cordova-plugin-nfc",
3
+ "version": "1.3.0",
4
+ "description": "Near Field Communication (NFC) Plugin. Read and write NDEF messages to NFC tags and share NDEF messages with peers.",
5
+ "cordova": {
6
+ "id": "phonegap-nfc",
7
+ "platforms": [
8
+ "android",
9
+ "wp8",
10
+ "windows",
11
+ "blackberry10",
12
+ "ios"
13
+ ]
14
+ },
15
+ "repository": "EYALIN/community-cordova-plugin-nfc/tree/master",
16
+ "keywords": [
17
+ "nfc",
18
+ "ndef",
19
+ "ecosystem:cordova",
20
+ "cordova",
21
+ "cordova-android",
22
+ "cordova-wp8",
23
+ "cordova-windows",
24
+ "cordova-blackberry10",
25
+ "cordova-ios"
26
+ ],
27
+ "author": "Don Coleman <don.coleman@gmail.com>",
28
+ "license": "MIT",
29
+ "homepage": "https://github.com/EYALIN/community-cordova-plugin-nfc/tree/master",
30
+ "funding": "https://github.com/sponsors/EYALIN",
31
+ "bugs": "https://github.com/EYALIN/community-cordova-plugin-nfc/issues"
32
+
33
+ }
package/plugin.xml ADDED
@@ -0,0 +1,147 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <plugin
3
+ xmlns="http://www.phonegap.com/ns/plugins/1.0"
4
+ xmlns:android="http://schemas.android.com/apk/res/android"
5
+ id="community-cordova-plugin-nfc"
6
+ version="1.3.0">
7
+
8
+ <name>NFC</name>
9
+
10
+ <description>Near Field Communication (NFC) Plugin. Read and write NDEF messages to NFC tags and share NDEF messages with peers.</description>
11
+
12
+ <license>MIT</license>
13
+ <keywords>nfc, NFC, NDEF</keywords>
14
+ <repo>https://github.com/EYALIN/community-cordova-plugin-nfc.git.git</repo>
15
+ <issue>https://github.com/EYALIN/community-cordova-plugin-nfc.git/issues</issue>
16
+
17
+ <platform name="android">
18
+ <js-module src="www/phonegap-nfc.js" name="NFC">
19
+ <runs />
20
+ </js-module>
21
+
22
+ <config-file target="res/xml/config.xml" parent="/*">
23
+ <feature name="NfcPlugin">
24
+ <param name="android-package" value="com.chariotsolutions.nfc.plugin.NfcPlugin"/>
25
+ <param name="onload" value="true" />
26
+ </feature>
27
+ </config-file>
28
+
29
+ <source-file src="src/android/src/com/chariotsolutions/nfc/plugin/NfcPlugin.java"
30
+ target-dir="src/com/chariotsolutions/nfc/plugin"/>
31
+ <source-file src="src/android/src/com/chariotsolutions/nfc/plugin/Util.java"
32
+ target-dir="src/com/chariotsolutions/nfc/plugin"/>
33
+
34
+ <config-file target="AndroidManifest.xml" parent="/manifest">
35
+ <uses-permission android:name="android.permission.NFC"/>
36
+ <uses-feature android:name="android.hardware.nfc" android:required="false"/>
37
+ </config-file>
38
+
39
+ </platform>
40
+
41
+ <platform name="wp8">
42
+ <js-module src="www/phonegap-nfc.js" name="NFC">
43
+ <runs />
44
+ </js-module>
45
+
46
+ <config-file target="config.xml" parent="/*">
47
+ <feature name="NfcPlugin">
48
+ <param name="wp-package" value="NfcPlugin"/>
49
+ </feature>
50
+ </config-file>
51
+
52
+ <config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
53
+ <Capability Name="ID_CAP_PROXIMITY" />
54
+ </config-file>
55
+
56
+ <source-file src="src/windows-phone-8/Ndef.cs" />
57
+ <source-file src="src/windows-phone-8/NfcPlugin.cs" />
58
+
59
+ </platform>
60
+
61
+ <!-- windows -->
62
+ <platform name="windows">
63
+ <js-module src="www/phonegap-nfc.js" name="NFC">
64
+ <runs />
65
+ </js-module>
66
+
67
+ <config-file target="config.xml" parent="/*">
68
+ <feature name="NfcPlugin">
69
+ <param name="wp-package" value="NfcPlugin"/>
70
+ </feature>
71
+ </config-file>
72
+
73
+ <config-file target="package.phone.appxmanifest" parent="/Package/Capabilities">
74
+ <DeviceCapability Name="proximity" />
75
+ </config-file>
76
+ <config-file target="package.windows.appxmanifest" parent="/Package/Capabilities">
77
+ <DeviceCapability Name="proximity" />
78
+ </config-file>
79
+ <config-file target="package.windows10.appxmanifest" parent="/Package/Capabilities">
80
+ <DeviceCapability Name="proximity" />
81
+ </config-file>
82
+ <config-file target="package.windows80.appxmanifest" parent="/Package/Capabilities">
83
+ <DeviceCapability Name="proximity" />
84
+ </config-file>
85
+
86
+ <js-module src="src/windows/nfc-plugin.js" name="NfcPlugin">
87
+ <merges target="" />
88
+ </js-module>
89
+ </platform>
90
+
91
+ <platform name="blackberry10">
92
+ <js-module src="www/phonegap-nfc.js" name="NFC">
93
+ <runs />
94
+ </js-module>
95
+ <!-- override defaults for BB10 -->
96
+ <js-module src="www/phonegap-nfc-blackberry.js" name="NFCBB10">
97
+ <runs />
98
+ </js-module>
99
+
100
+ <!-- "native" implementation -->
101
+ <source-file src="src/blackberry10/index.js" />
102
+
103
+ <config-file target="www/config.xml" parent="/widget">
104
+ <!-- Note: mapping is broken in Cordova 3.1.0-0.2.0 -->
105
+ <feature name="NfcPlugin" value="com.chariotsolutions.nfc.plugin" />
106
+ </config-file>
107
+ </platform>
108
+
109
+ <platform name="ios">
110
+ <js-module src="www/phonegap-nfc.js" name="NFC">
111
+ <runs />
112
+ </js-module>
113
+
114
+ <config-file parent="/*" target="config.xml">
115
+ <feature name="NfcPlugin">
116
+ <param name="ios-package" value="NfcPlugin" />
117
+ </feature>
118
+ </config-file>
119
+
120
+ <!-- https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_nfc_readersession_formats?language=objc -->
121
+ <config-file parent="com.apple.developer.nfc.readersession.formats" platform="ios" target="*-Debug.plist">
122
+ <array>
123
+ <string>NDEF</string>
124
+ <string>TAG</string>
125
+ </array>
126
+ </config-file>
127
+ <config-file parent="com.apple.developer.nfc.readersession.formats" platform="ios" target="*-Release.plist">
128
+ <array>
129
+ <string>NDEF</string>
130
+ <string>TAG</string>
131
+ </array>
132
+ </config-file>
133
+
134
+ <header-file src="src/ios/NfcPlugin.h" />
135
+ <source-file src="src/ios/NfcPlugin.m" />
136
+
137
+ <!-- frameworks -->
138
+ <framework src="CoreNFC.framework" weak="true" />
139
+
140
+ <preference name="NFC_USAGE_DESCRIPTION" default="Read NFC Tags" />
141
+ <config-file target="*-Info.plist" parent="NFCReaderUsageDescription">
142
+ <string>$NFC_USAGE_DESCRIPTION</string>
143
+ </config-file>
144
+ </platform>
145
+
146
+
147
+ </plugin>