Skip to content

Commit

Permalink
implementing bluetooth status
Browse files Browse the repository at this point in the history
  • Loading branch information
joe committed Aug 7, 2014
1 parent 1f132e0 commit 3dd11b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Classes/OrgBeuckmanTibeaconsModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
@import CoreLocation;
@import CoreBluetooth;

@interface OrgBeuckmanTibeaconsModule : TiModule <CLLocationManagerDelegate, CBPeripheralManagerDelegate>
@interface OrgBeuckmanTibeaconsModule : TiModule <CLLocationManagerDelegate, CBPeripheralManagerDelegate, CBCentralManagerDelegate>
{
CBPeripheralManager *peripheralManager;
CLBeaconRegion *beaconRegion;

NSMutableDictionary *beaconProximities;
CLLocationManager *_locationManager;
CBCentralManager *bluetoothManager;
}

@end
39 changes: 39 additions & 0 deletions Classes/OrgBeuckmanTibeaconsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ -(void)startup

beaconProximities = [[NSMutableDictionary alloc] init];

[self detectBluetooth];

NSLog(@"[INFO] %@ loaded",self);
}

Expand Down Expand Up @@ -618,4 +620,41 @@ - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)pManager
}


#pragma mark - Bluetooth enabled status management

- (void)detectBluetooth
{
if(!bluetoothManager)
{
bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
}
[self centralManagerDidUpdateState:bluetoothManager]; // Show initial state
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
NSString *stateString = nil;
switch(bluetoothManager.state)
{
case CBCentralManagerStateResetting: stateString = @"resetting"; break;
case CBCentralManagerStateUnsupported: stateString = @"unsupported"; break;
case CBCentralManagerStateUnauthorized: stateString = @"unauthorized"; break;
case CBCentralManagerStatePoweredOff: stateString = @"off"; break;
case CBCentralManagerStatePoweredOn: stateString = @"on"; break;
default: stateString = @"unknown"; break;
}

NSDictionary *status = [[NSDictionary alloc] initWithObjectsAndKeys: stateString, @"status", nil];

[self fireEvent:@"bluetoothStatus" withObject:status];
[status autorelease];

}
- (void)requestBluetoothStatus:(id)args
{
[self centralManagerDidUpdateState:bluetoothManager];
}



@end
Binary file not shown.
2 changes: 1 addition & 1 deletion manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 0.9
version: 0.9.1
apiversion: 2
description: Implements iBeacon monitoring and ranging and advertising
author: Joe Beuckman
Expand Down

0 comments on commit 3dd11b3

Please sign in to comment.