Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
= 0.7.3 =
Bump version for npm issues

= 0.7.2 =
Add support for WKWebView #288 Thanks andreamaioli

= 0.7.1 =
Automatically Add NFC entitlement for iOS #285 Thanks andreamaioli

= 0.7.0 =
Add iOS support #139
Fixed language code field length detection #219 Thanks homer-jay
Fixed java.util.ConcurrentModificationException #231 Thanks João Gonçalves (Chuckytuh)
Documentation fixes #224 Thanks Tom Brückner (derwaldgeist)

= 0.6.6 =
Update Windows platforms (includes Windows Phone 8.1)
* tag event contains nested ndefMessage object #215
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2011-2015 Chariot Solutions
Copyright (c) 2011-2017 Chariot Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
74 changes: 70 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This plugin uses NDEF (NFC Data Exchange Format) for maximum compatibilty betwee
Supported Platforms
-------------------
* Android
* [iOS 11](#ios-notes)
* Windows (includes Windows Phone 8.1, Windows 8.1, Windows 10)
* BlackBerry 10
* Windows Phone 8
Expand Down Expand Up @@ -59,6 +60,16 @@ BlackBerry 7 support is only available for Cordova 2.x. For applications targeti

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.

## iOS Notes

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.

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 new iOS specific functions [nfc.beginSession](#nfcbeginsession) and [nfc.invalidateSession](#nfcinvalidatesession).

You must call [nfc.beginSession](#nfcbeginsession) before every scan.

The initial iOS version plugin does not support scanning multiple tags (invalidateAfterFirstRead:FALSE) or setting the alertMessage. If you have use cases or suggestions on the best way to support multi-read or alert messages, open a ticket for discussion.

# NFC

> The nfc object provides access to the device's NFC sensor.
Expand All @@ -81,6 +92,8 @@ See [Getting Started](https://github.com/chariotsolutions/phonegap-nfc/blob/mast
- [nfc.stopHandover](#nfcstophandover)
- [nfc.enabled](#nfcenabled)
- [nfc.showSettings](#nfcshowsettings)
- [nfc.beginSession](#nfcbeginsession)
- [nfc.invalidateSession](#nfcinvalidatesession)

## nfc.addNdefListener

Expand All @@ -104,9 +117,12 @@ For BlackBerry 10, you must configure the type of tags your application will rea

On Android registered [mimeTypeListeners](#nfcaddmimetypelistener) takes precedence over this more generic NDEF listener.

On iOS you must call [beingSession](#nfcbeginsession) before scanning a tag.

### Supported Platforms

- Android
- iOS
- Windows
- BlackBerry 7
- BlackBerry 10
Expand All @@ -127,6 +143,7 @@ Removes the previously registered event listener for NDEF tags added via `nfc.ad
### Supported Platforms

- Android
- iOS
- Windows
- BlackBerry 7

Expand Down Expand Up @@ -154,6 +171,8 @@ This event occurs when any tag is detected by the phone.
- Windows
- BlackBerry 7

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.

## nfc.removeTagDiscoveredListener

Removes the previously registered event listener added via `nfc.addTagDiscoveredListener`.
Expand Down Expand Up @@ -201,7 +220,6 @@ On Android, MIME types for filtering should always be lower case. (See [IntentFi
### Supported Platforms

- Android
- Windows
- BlackBerry 7

## nfc.removeMimeTypeListener
Expand Down Expand Up @@ -506,8 +524,56 @@ Windows will return **NO_NFC_OR_NFC_DISABLED** when NFC is not present or disabl
### Supported Platforms

- Android
- iOS
- Windows

## nfc.beginSession

iOS requires you to begin a session before scanning a NFC tag.

nfc.beginSession(success, failure);

### Description

Function `beginSession` starts the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) allowing iOS to scan NFC tags.

### Parameters

- __success__: Success callback function called when the session begins [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]

### Quick Example

nfc.beginSession();

### Supported Platforms

- iOS

## nfc.invalidateSession

Invalidate the NFC session.

nfc.invalidateSession(success, failure);

### Description

Function `invalidateSession` stops the [NFCNDEFReaderSession](https://developer.apple.com/documentation/corenfc/nfcndefreadersession) returning control to your app.

### Parameters

- __success__: Success callback function called when the session in invalidated [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]

### Quick Example

nfc.invalidateSession();

### Supported Platforms

- iOS


# NDEF

> The `ndef` object provides NDEF constants, functions for creating NdefRecords, and functions for converting data.
Expand Down Expand Up @@ -588,7 +654,7 @@ The tag contents are platform dependent.

`id` and `techTypes` may be included when scanning a tag on Android. `serialNumber` may be included on BlackBerry 7.

`id` and `serialNumber` are different names for the same value. `id` is typically displayed as a hex string `ndef.bytesToHexString(tag.id)`.
`id` and `serialNumber` are different names for the same value. `id` is typically displayed as a hex string `nfc.bytesToHexString(tag.id)`.

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.

Expand Down Expand Up @@ -663,7 +729,7 @@ You can also log the tag contents in your event handlers. `console.log(JSON.str

## Non-NDEF Tags

Only Android and BlackBerry 7 can read data from non-NDEF NFC tags.
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.

## Mifare Classic Tags

Expand Down Expand Up @@ -833,7 +899,7 @@ License

The MIT License

Copyright (c) 2011-2015 Chariot Solutions
Copyright (c) 2011-2017 Chariot Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "phonegap-nfc",
"version": "0.6.6",
"version": "0.7.3",
"description": "Near Field Communication (NFC) Plugin. Read and write NDEF messages to NFC tags and share NDEF messages with peers.",
"cordova": {
"id": "phonegap-nfc",
"platforms": [
"android",
"wp8",
"windows",
"blackberry10"
"blackberry10",
"ios"
]
},
"repository": {
Expand All @@ -23,7 +24,8 @@
"cordova-android",
"cordova-wp8",
"cordova-windows",
"cordova-blackberry10"
"cordova-blackberry10",
"cordova-ios"
],
"author": "Don Coleman <don.coleman@gmail.com>",
"license": "MIT",
Expand Down
37 changes: 36 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="phonegap-nfc"
version="0.6.6">
version="0.7.3">

<name>NFC</name>

Expand Down Expand Up @@ -103,5 +103,40 @@
</config-file>
</platform>

<platform name="ios">
<js-module src="www/phonegap-nfc.js" name="NFC">
<runs />
</js-module>

<config-file parent="/*" target="config.xml">
<feature name="NfcPlugin">
<param name="ios-package" value="NfcPlugin" />
</feature>
</config-file>

<config-file platform="ios" target="*-Debug.plist" parent="com.apple.developer.nfc.readersession.formats">
<array>
<string>NDEF</string>
</array>
</config-file>

<config-file platform="ios" target="*-Release.plist" parent="com.apple.developer.nfc.readersession.formats">
<array>
<string>NDEF</string>
</array>
</config-file>

<header-file src="src/ios/NfcPlugin.h" />
<source-file src="src/ios/NfcPlugin.m" />

<!-- frameworks -->
<framework src="CoreNFC.framework" />

<preference name="NFC_USAGE_DESCRIPTION" default="Read NFC Tags" />
<config-file target="*-Info.plist" parent="NFCReaderUsageDescription">
<string>$NFC_USAGE_DESCRIPTION</string>
</config-file>
</platform>


</plugin>
28 changes: 28 additions & 0 deletions src/ios/NfcPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// NfcPlugin.h
// PhoneGap NFC - Cordova Plugin
//
// (c) 2107 Don Coleman

#ifndef NfcPlugin_h
#define NfcPlugin_h

#import <Cordova/CDV.h>
#import <CoreNFC/CoreNFC.h>
#import <WebKit/WebKit.h>

@interface NfcPlugin : CDVPlugin <NFCNDEFReaderSessionDelegate> {
}

// iOS Specific API
- (void)beginSession:(CDVInvokedUrlCommand *)command;
- (void)invalidateSession:(CDVInvokedUrlCommand *)command;

// Standard PhoneGap NFC API
- (void)registerNdef:(CDVInvokedUrlCommand *)command;
- (void)removeNdef:(CDVInvokedUrlCommand *)command;
- (void)enabled:(CDVInvokedUrlCommand *)command;

@end

#endif
Loading