blackberry / WebWorks-Community-APIs

Community owned repository containing JavaScript Extensions for BlackBerry WebWorks
Apache License 2.0
140 stars 204 forks source link

How to use this plugin cordova-plugin-beacon? #434

Open aubrey-fowler opened 6 years ago

aubrey-fowler commented 6 years ago

I am just getting started with this plugin and I'm not sure what I need to do.

I am writing an app with Cordova cli v8, Ionic 1.3.4, and AngularJS 1.5.3.

Here is my controller:

app.controller('myCtrl', function($scope) {

    $scope.version = 0;
    $scope.result = {};
    $scope.running = 0;

    $scope.onClick = onClick;
    $scope.stop = stop;

    function onClick() {

        console.log(' on click ');

        $scope.running = 0;

        cordova.plugins.simplexpbeacon.initialiseBluetooth(
            function(data) {
                var json = JSON.parse(data);
                if (json.status === 'OK') {

                    console.log(' initialiseBluetooth ', json);

                }
            }, onError
        );

        cordova.plugins.simplexpbeacon.pluginVersion(onSuccess, onError);

        cordova.plugins.simplexpbeacon.startMonitoring(function (response) {
            console.log(' startMonitoring ', response);
            $scope.running++;

            $scope.result = JSON.parse(response);

        }, onError);

    }

    function stop() {

        cordova.plugins.simplexpbeacon.stopMonitoring(function (response) {
            console.log(response);
        }, onError);

    }

    function onSuccess(result) {
        console.log(result);
        $scope.version = JSON.parse(result).plugin_version;
    }

    function onError(error) {
        console.log(error);
    }

});

Do I need to call initialiseBluetooth each time I click on the button or just when the application runs?

startMonitoring is called but it never gets any updates or new data.

I am not sure if what I am doing is correct or what I need to do. I want the user to push a button and then start scanning for ibeacon tiles.