Skip to content

Commit

Permalink
see description for usage:
Browse files Browse the repository at this point in the history
```
// android ibeacon module
          Alloy.Globals.iBeacons = require('com.drtech.altbeacon');
          // ibeacon protocol parser
          Alloy.Globals.iBeacons.addBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
          Alloy.Globals.iBeacons.bindBeaconService();

  if(Alloy.Globals.iBeacons.isBLESupported()) {
          if(Alloy.Globals.iBeacons.checkAvailability()) {

            console.log("checkavailability ", Alloy.Globals.iBeacons.checkAvailability());
            // now we need the timer to loop and check until beacons become available...
            var ibeaconreadycheckinterval;
            var iibeacon = 0;

            Alloy.Globals.iBeacons.addEventListener("serviceBound", function bleServiceBound(e){
              Alloy.Globals.iBeacons.removeEventListener("serviceBound", bleServiceBound);
              console.log("Okay! BLE is ready!");

              // disable battery lurking autoranging.
              Alloy.Globals.iBeacons.disableAutoRanging();

              // fire up actual monitoring for beacons.
              startBLE();
            });

}

}
```
  • Loading branch information
roelandp authored Jun 10, 2019
0 parents commit 0d33448
Showing 1 changed file with 0 additions and 0 deletions.
Binary file added com.drtech.altbeacon-android-3.0.0.zip
Binary file not shown.

4 comments on commit 0d33448

@olli3
Copy link

@olli3 olli3 commented on 0d33448 Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now works ! thank you

can i be cheeky and see your startBLE too ?

@olli3
Copy link

@olli3 olli3 commented on 0d33448 Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now doesnt throw errors but never ever finds any beacons or calls handleRegionEnter

if(Alloy.Globals.TiBeacons.isBLESupported()) {
if(Alloy.Globals.TiBeacons.checkAvailability()) {

            console.log("checkavailability ", Alloy.Globals.TiBeacons.checkAvailability());
            // now we need the timer to loop and check until beacons become available...
            var ibeaconreadycheckinterval;
            var iibeacon = 0;

            Alloy.Globals.TiBeacons.addEventListener("serviceBound", function bleServiceBound(e){
                Alloy.Globals.TiBeacons.removeEventListener("serviceBound", bleServiceBound);
                console.log("Okay! BLE is ready!");

                // disable battery lurking autoranging.
                Alloy.Globals.TiBeacons.disableAutoRanging();

                // fire up actual monitoring for beacons.
                Alloy.Globals.TiBeacons.addEventListener("enteredRegion", handleRegionEnter);
                Alloy.Globals.TiBeacons.addEventListener("exitedRegion", handleRegionExit);
                Alloy.Globals.TiBeacons.addEventListener("beaconRanges", handleBeaconRanges);
                Alloy.Globals.TiBeacons.addEventListener("beaconProximity", handleProximityEvent);

                Alloy.Globals.TiBeacons.startMonitoringForRegion({
                identifier: 'Region by UUID only',
                uuid: Alloy.Globals.UUID
                });

                Alloy.Globals.TiBeacons.startMonitoringForRegion({
                        uuid : Alloy.Globals.UUID,
                        identifier : Alloy.Globals.Identifier+'-UUID-MAJOR1',
                        major : 1,
                        //minor : < your beacon minor >,
                });


                Alloy.Globals.TiBeacons.startMonitoringForRegion({
                        uuid : Alloy.Globals.UUID,
                        identifier : Alloy.Globals.Identifier+'-UUID-MAJOR1-MINOR1',
                        major : 1,
                        minor : 1,
                });

                Alloy.Globals.TiBeacons.startMonitoringForRegion({
                        uuid : Alloy.Globals.UUID,
                        identifier : Alloy.Globals.Identifier+'-UUID-MAJOR1-MINOR2',
                        major : 1,
                        minor : 2,
                });

            });

        }
    } else {

    }

@olli3
Copy link

@olli3 olli3 commented on 0d33448 Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function handleRegionEnter(e) {
if(OS_ANDROID) {
Ti.API.info("handleRegionEnter" + JSON.stringify(e));

     //Ti.API.info('---------------------------');
     //Ti.API.info('enterRegion triggered');
     Ti.API.info(e.identifier);
     //Ti.API.info('---------------------------');
     var model = ensureModel(e);
     //Alloy.Globals.UUIDNotified = false;
     Alloy.Globals.TiBeacons.startRangingForBeacons(e);
     return true;
 } else {
     return false;
 }

}

function handleRegionExit(e) {
if(OS_ANDROID) {
Ti.API.info("handleRegionExit" + JSON.stringify(e));

     var model = ensureModel(e);
     Alloy.Collections.iBeacon.remove(model);
     Alloy.Globals.TiBeacons.stopRangingForBeacons(e);
     //Alloy.Globals.UUIDNotified = false;
     return true;
 } else {
     return false;
 }

}

@olli3
Copy link

@olli3 olli3 commented on 0d33448 Jun 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last comment : guessing this could be a location permission issue does this have to be enabled?

Please sign in to comment.