I'm working on my first bluetooth app. For now i've an AppUIview that implements a button that call a function in the AppCentralManager where the bluetooth function will be implemented:
- (IBAction) Scan{
NSLog(@"scan function");
[[AppBluetoothCenter alloc]initialize];
}
in the AppBluetoothCenter.h i've declaration those functions:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import <CoreBluetooth/CBService.h>
#import "AppDelegate.h"
@interface AppBluetoothCenter : NSObject <UIApplicationDelegate,CBCentralManagerDelegate, CBPeripheralDelegate>
@property CBCentralManager* CentralManager;
- (void) initialize;
@end
in the AppBluetoothCenter.m i've implemented the functions:
#import "AppBluetoothCenter.h"
@implementation AppBluetoothCenter
-(void)initialize{
NSLog(@"initialize");
_CentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerStatePoweredOff){
NSLog(@"BLE OFF");
}
else if (central.state == CBCentralManagerStatePoweredOn){
NSLog(@"BLE ON");
}
else if (central.state == CBCentralManagerStateUnknown){
NSLog(@"NOT RECOGNIZED");
}
else if(central.state == CBCentralManagerStateUnsupported){
NSLog(@"BLE NOT SUPPORTED");
}
}
@end
Running app in the log console i receive:
AppBluetooth[1273:60b] scan function
AppBluetooth[1273:60b] initialize
Why centralManagerDidUpdateState it's not be called?