GithubHelp home page GithubHelp logo

Comments (1)

stephenrob avatar stephenrob commented on September 28, 2024

I've currently not looked into typescript and angular2. The application we are developing with Ionic is still Ionic v1 and Angular 1.5.3 (I'm just cleaning up some of the code before open sourcing this).

Below is an extract from one of our AngularJS services that uses the BackgroundBeaconMonitoring Plugin.

Once you have added the plugin the javascript files should be available to use, they are auto included like all other plugin files, make sure you have android added to your project as this plugin currently only works for android. At this stage you can just call the plugin methods documented in the README.

In most cases you will need to customise the code in this plugin, generally the BeaconLoggingMonitorNotifier and BeaconLoggingRangeNotifier to suit your individual application needs, not just adding the plugin.

angular.module('myJourneys.services').service('BeaconMonitoringService', function($rootScope,
                                                                                  $ionicPlatform,
                                                                                  $cordovaBeacon,
                                                                                  $cordovaLocalNotification,
                                                                                  $cordovaDevice,
                                                                                  BEACON_UUID,
                                                                                  BEACON_GLOBAL_MAJOR,
                                                                                  BEACON_GLOBAL_MINOR,
                                                                                  BEACON_REGIONS,
                                                                                  API_SERVER_URL,
                                                                                  API_VERSION,
                                                                                  PreferencesService,
                                                                                  RegionEventsService,
                                                                                  BeaconEventsService,
                                                                                  AuthService,
                                                                                  $timeout) {

  var BeaconMonitoring = function() {};

  ...

  var requestPermissions = function() {
    $cordovaBeacon.requestAlwaysAuthorization();
    $cordovaLocalNotification.promptForPermission();
    BackgroundBeaconMonitoring.requestPermissions();
  };

  var initAndroidService = function() {

    $ionicPlatform.ready(function() {

      var device_id = $cordovaDevice.getUUID();

      BackgroundBeaconMonitoring.startService(AuthService.token(), AuthService.email(), device_id, API_SERVER_URL, API_VERSION, PreferencesService.readSendMovement(), function() {

        BEACON_REGIONS.forEach(function(region) {

          var identifier = region.identifier;
          var uuid, major, minor = "";

          if (region.uuid === undefined) {
            uuid = BEACON_UUID;
          } else {
            uuid = region.uuid;
          }
          if (region.major === undefined) {
            major = BEACON_GLOBAL_MAJOR;
          } else {
            major = region.major;
          }
          if (region.minor === undefined) {
            minor = BEACON_GLOBAL_MINOR;
          } else {
            minor = region.minor;
          }

          BackgroundBeaconMonitoring.startMonitoringRegion(identifier, uuid, major, minor, function() {}, function() {});
          BackgroundBeaconMonitoring.startRangingRegion(identifier, uuid, major, minor, function() {}, function() {});

        });

      }, function() {});

    });

  };

  BeaconMonitoring.prototype.init = function() {

    $ionicPlatform.ready(function() {

      requestPermissions();

      ...

      initAndroidService();

    });

  };

  return BeaconMonitoring;

});

from background-beacon-monitoring.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.