diff --git a/Classes/OrgBeuckmanTibeaconsModule.h b/Classes/OrgBeuckmanTibeaconsModule.h index 6813d64..9422b0b 100644 --- a/Classes/OrgBeuckmanTibeaconsModule.h +++ b/Classes/OrgBeuckmanTibeaconsModule.h @@ -5,13 +5,14 @@ @import CoreLocation; @import CoreBluetooth; -@interface OrgBeuckmanTibeaconsModule : TiModule +@interface OrgBeuckmanTibeaconsModule : TiModule { CBPeripheralManager *peripheralManager; CLBeaconRegion *beaconRegion; NSMutableDictionary *beaconProximities; CLLocationManager *_locationManager; + CBCentralManager *bluetoothManager; } @end diff --git a/Classes/OrgBeuckmanTibeaconsModule.m b/Classes/OrgBeuckmanTibeaconsModule.m index ca233a8..24f964c 100644 --- a/Classes/OrgBeuckmanTibeaconsModule.m +++ b/Classes/OrgBeuckmanTibeaconsModule.m @@ -34,6 +34,8 @@ -(void)startup beaconProximities = [[NSMutableDictionary alloc] init]; + [self detectBluetooth]; + NSLog(@"[INFO] %@ loaded",self); } @@ -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 diff --git a/TiBeacons.xcodeproj/project.xcworkspace/xcuserdata/innovator.xcuserdatad/UserInterfaceState.xcuserstate b/TiBeacons.xcodeproj/project.xcworkspace/xcuserdata/innovator.xcuserdatad/UserInterfaceState.xcuserstate index c3d89d6..2e56591 100644 Binary files a/TiBeacons.xcodeproj/project.xcworkspace/xcuserdata/innovator.xcuserdatad/UserInterfaceState.xcuserstate and b/TiBeacons.xcodeproj/project.xcworkspace/xcuserdata/innovator.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/manifest b/manifest index 469242d..6a5eac9 100644 --- a/manifest +++ b/manifest @@ -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