Sample iBeacon project not working on Cordova?

Ask, and ye shall receive.
graffitici
Posts: 5
Joined: 06:49, 08 Dec 2014

Sample iBeacon project not working on Cordova?

Postby graffitici » 06:20, 10 Dec 2014

Hi,

I am absolutely amazed by the EvoThings project! I wrote up an application based on iBeacon, and tested it with EvoThings. Now, I'd like to package it as its own Cordova app. I followed the instructions, but nothing happens when I run it. I started debugging it from Safari, and found out that the problematic line is the following:

https://github.com/evothings/evothings-examples/blob/master/examples/ibeacon-scan/app.js#L43

Namely, I get the error:

Code: Select all

undefined is not a function (evaluating 'locationManager.delegate.implement')


Looks like locationManager.delegate does not have a function called implement.

I have the following plugins:

Code: Select all

$ cordova plugins info
com.evothings.ble 0.0.1 "Evothings BLE API"
com.unarin.cordova.beacon 3.2.2 "Proximity Beacon Plugin"
de.appplant.cordova.plugin.local-notification 0.7.6 "LocalNotification"
org.apache.cordova.console 0.2.11 "Console"
org.apache.cordova.device 0.2.12 "Device"
org.apache.cordova.geolocation 0.3.10 "Geolocation"


Am I missing something? How can I run this example as its own Cordova app? Do I have to change any settings in the Xcode project?

Thanks!

graffitici
Posts: 5
Joined: 06:49, 08 Dec 2014

Re: Sample iBeacon project not working on Cordova?

Postby graffitici » 06:27, 10 Dec 2014

By the way, I should specify that I am working on the iOS platform. I see the following output on the Xcode console:

Code: Select all

2014-12-10 00:25:08.933 iBeaconTest[3775:1246783] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/0BE8CB68-6AF5-406F-ACAF-D7A39A552CCA/Library/Cookies/Cookies.binarycookies
2014-12-10 00:25:09.158 iBeaconTest[3775:1246783] Apache Cordova native platform version 3.7.0 is starting.
2014-12-10 00:25:09.159 iBeaconTest[3775:1246783] Multi-tasking -> Device: YES, App: YES
2014-12-10 00:25:09.163 iBeaconTest[3775:1246783] Unlimited access to network resources
2014-12-10 00:25:09.168 iBeaconTest[3775:1246783]

Started backup to iCloud! Please be careful.
Your application might be rejected by Apple if you store too much data.
For more information please read "iOS Data Storage Guidelines" at:
https://developer.apple.com/icloud/documentation/data-storage/
To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file

2014-12-10 00:25:09.288 iBeaconTest[3775:1246783] [CDVTimer][localnotification] 0.609994ms
2014-12-10 00:25:09.288 iBeaconTest[3775:1246783] [CDVTimer][localnotification] 0.014007ms
2014-12-10 00:25:09.288 iBeaconTest[3775:1246783] [CDVTimer][TotalPluginStartup] 1.190960ms
2014-12-10 00:25:10.102 iBeaconTest[3775:1246783] Resetting plugins due to page load.
2014-12-10 00:25:10.393 iBeaconTest[3775:1246783] Finished load of: file:///private/var/mobile/Containers/Bundle/Application/A09338DD-B588-4691-B740-28238084429B/iBeaconTest.app/www/index.html
2014-12-10 00:25:10.510 iBeaconTest[3775:1246813] [DOM] registerDelegateCallbackId()
2014-12-10 00:25:10.526 iBeaconTest[3775:1246844] Registering delegate callback ID: LocationManager1771431342
2014-12-10 00:25:10.528 iBeaconTest[3775:1246844] [DOM] _onDelegateCallback() null
2014-12-10 00:25:10.548 iBeaconTest[3775:1246783] didChangeAuthorizationStatus
2014-12-10 00:25:10.548 iBeaconTest[3775:1246783] didChangeAuthorizationStatus: 0 => AuthorizationStatusNotDetermined
2014-12-10 00:25:10.549 iBeaconTest[3775:1246783] Converted locationManager:didChangeAuthorizationStatus: into didChangeAuthorizationStatus
2014-12-10 00:25:10.549 iBeaconTest[3775:1246783] peripheralManagerDidUpdateState() state: PeripheralManagerStatePoweredOn
2014-12-10 00:25:10.550 iBeaconTest[3775:1246844] peripheralManagerDidUpdateState: PeripheralManagerStatePoweredOn
2014-12-10 00:25:10.550 iBeaconTest[3775:1246844] Converted peripheralManagerDidUpdateState: into peripheralManagerDidUpdateState
2014-12-10 00:25:10.552 iBeaconTest[3775:1246844] [DOM] _mapDelegateCallback() found eventType didChangeAuthorizationStatus
2014-12-10 00:25:10.552 iBeaconTest[3775:1246844] [DOM] DEFAULT didChangeAuthorizationStatus()
2014-12-10 00:25:10.553 iBeaconTest[3775:1246844] [DOM] _onDelegateCallback() {"state":"PeripheralManagerStatePoweredOn","eventType":"peripheralManagerDidUpdateState"}
2014-12-10 00:25:10.553 iBeaconTest[3775:1246844] [DOM] _mapDelegateCallback() found eventType peripheralManagerDidUpdateState
2014-12-10 00:25:10.553 iBeaconTest[3775:1246844] [DOM] DEFAULT peripheralManagerDidUpdateState()
2014-12-10 00:25:10.552 iBeaconTest[3775:1246813] [DOM] _onDelegateCallback() {"status":"AuthorizationStatusNotDetermined","eventType":"didChangeAuthorizationStatus"}

graffitici
Posts: 5
Joined: 06:49, 08 Dec 2014

Re: Sample iBeacon project not working on Cordova?

Postby graffitici » 18:07, 10 Dec 2014

Ah ok, I got it. I think the example uses an outdated API (or I have a development version of the beacon plugin). Instead of using

Code: Select all

var delegate = locationManager.delegate.implement({
...
});
locationManager.setDelegate(delegate);


One has to do

Code: Select all

var delegate = locationManager.Delegate();
delegate.didStartMonitoringForRegion = function(p) {
...
};
locationManager.setDelegate(delegate);

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Sample iBeacon project not working on Cordova?

Postby micke » 11:47, 11 Dec 2014

Hi, thanks for detailing this issue!

Did some testing and looked at the plugin source code, and there are some inconsistencies and version issues, as you point out.

What I found that in the version of cordova-plugin-ibeacon that is included with Evothings Client 1.0.0, the API is indeed a bit outdated and the documentation looks misleading at some points.

These styles work for me:

Code: Select all

var delegate = cordova.plugins.delegate.implement(
...

var delegate = new cordova.plugins.locationManager.Delegate();
...


These are listed in the README file and in the source code comments of the previous version, but do NOT work:

Code: Select all

var delegate = cordova.plugins.Delegate().implement(
...

var delegate = cordova.plugins.Delegate.implement(
...


In the new version the documentation has been updated and use the API you are using.

The API you are using seems to be the one to go for, since it works in both older and newer versions of the plugin. It is also cleaner in my point of view. Will update the iBeacon Scan example app to use this style.

Thanks a lot for reporting this issue!

Best, Mikael

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Sample iBeacon project not working on Cordova?

Postby micke » 12:17, 11 Dec 2014

Regarding how to build a stand-alone Cordova app from the iBeacon Scan example, here are the steps to do this.

Initial setup to create the project:

  • Create a new Cordova project
  • Delete the contents of the www folder
  • Copy in the files in the ibeacon-scan folder to the www folder
  • Add the cordova-plugin-ibeacon plugin
  • Add the target platforms (ios and/or android)

For each code change:

  • Build for the target platforms

Something like this, first the initial setup:

Code: Select all

cordova create ibeaconapp com.mydomain.ibeaconapp iBeaconApp
cd ibeaconapp
(delete files in www, using file browser or command line)
(copy files from examples/ibeacon-scan to www, using file browser or command line)
cordova plugin add https://github.com/petermetz/cordova-plugin-ibeacon.git
cordova platform add ios
cordova platform add android


Then build and install the app:

Code: Select all

cordova build ios
cordova build android
adb install -r platforms/android/ant-build/iBeaconApp-debug.apk
(for iOS open and run the generated project using Xcode: platforms/ios/iBeaconApp.xcodeproj)


To save development time, you can use Evothings Workbench with any Cordova app. This gives you fast reload-on-save with your own app (in this case you do not use Evothings Client). This is useful for example if you wish yo use plugins not included in Evothings Client.

Instructions are found here:

http://evothings.com/doc/build/cordova- ... rEvothings

Here is a guide for how to install Cordova in case someone reading this does not have Cordova installed:

http://evothings.com/doc/build/build-ov ... ml#Install

Best regards, Mikael


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 3 guests