This Cordova app demonstrates how you can use the Radius Networks ProximityKit Cordova/PhoneGap plugin in your own project.
This project contains everything you need to build a running version of the "Hello Beacon" Cordova app on iOS and Android with one exception:
You must install your own ProximityKit.plist and ProximityKit.properties files!
Otherwise the app will not recognize any of your beacons. Make sure you have at least one of your beacons powered up before you run the sample app, or it won't be very interesting!
In order to see the demo app working with your own beacons, download the ProximityKit.plist (for iOS) and/or ProximityKit.properties (for Android) for your kit. These files need to be in the following location within your project depending on the platform being built:
| Platform | Location of ProximityKit configuration file |
|---|---|
| iOS | ./platforms/ios/Hello Beacon/ProximityKit.plist |
| Android | ./platforms/android/src/ProximityKit.properties |
In addition to placing the ProximityKit.plist file inside the iOS project's directory structure, you need to add the file to the Xcode project and to the appropriate target:
-
Open the project in Xcode
platforms/ios/Hello Beacon.xcodeproj -
Select the Hello Beacon target and select "Add Files to 'Hello Beacon'" from the File menu.
-
Locate your ProximityKit.plist file and click "Add"
In order to ensure that you're using the latest version of the ProximityKit Cordova plugin, it is not included in this repository. To add the plugin:
$ cordova plugin add https://github.com/RadiusNetworks/proximitykit-plugin-cordova
You also need to add the Cordova console plugin:
$ cordova plugin add org.apache.cordova.console
For iOS, Proximity Kit uses SQLite internally but just needs the default library included on iOS. So you need to link to it in the project in Xcode manually after the app is built in Cordova/PhoneGap. To do this, open the generated Xcode project found under platforms/ios and follow these steps:
- Select the App's target in Xcode
- Choose "Build Phases"
- Under the "Link Binary With Libraries" section click the '+' to add another library
- Choose libsqlite3.dylib and click "Add"
To properly implement the custom application subclass that initiates the beacon monitoring, edit the AndroidManifest.xml file (platforms/android/AndroidManifest.xml) to include the proper android:name tag under application for the ProximityKitCordovaAppication class. The application header should look like this:
<application android:name="com.radiusnetworks.cordova.proximitykit.ProximityKitCordovaApplication" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
Adding the plugin will also modify other parts of your AndroidManifest.xml automatically. Please do not remove the <service>, <receiver>, and <uses-permission> elements that are added to this file or the plugin will not work properly.
The app needs to be running on a Bluetooth LE-enabled device in order to be able to range beacons. Your device should have already been setup as a developer device for iOS.
Note that running the app from the command line for iOS is extremely slow for some reason. Running the app from Xcode is definitely recommended.
To build, install, and run the app on your iOS device, execute the following command in the project directory:
$ cordova run --device ios
Similarly for Android:
$ cordova run --device android
-
Open the following project in Xcode if you have not already done so:
platforms/ios/Hello Beacon.xcodeproj -
Select the "Hello Beacon" scheme and your iOS device.
-
Run the app by choosing "Run" from the "Product" menu.