我正在尝试扫描广告外围设备,我有一些广告用于测试目的。
我在单例文件中将我的核心蓝牙方法作为应用程序的管理员
这是我的.h
@interface MyBluetoothManager : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate>
这些方法都在我的.m
+ (MyBluetoothManager *)sharedInstance {
static dispatch_once_t pred = 0;
__strong static AGBluetoothManager *_sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = [[self alloc] init];
});
return _sharedObject;
}
- (id)init {
if (self = [super init]) {
self.cbCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
return self;
}
- (void)startScan {
if (self.isBluetoothPowerOn) {
if (!self.isCBReady) {
[self printLog:@"Scanning for devices..."];
[self.cbCentralManager scanForPeripheralsWithServices:nil options:nil];
}
} else {
NSLog(@"Bluetooth NOT on, turn on bluetooth from settings");
}
}
- (void)centralmanager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"Did discover peripheral. peripheral: %@ rssi: %@, UUID: %@ advertisementData: %@ ", peripheral, RSSI, peripheral.identifier, advertisementData);
//....
//...
}
我在另一个课程中有IBOutlet操作,当我点击它时会触发startScan
[MyBluetoothManager sharedInstance] startScan];
然后我在调试器CoreBluetooth BLE hardware is powered on and ready
然后scanning for devices...
中收到这些消息,但除了didDiscoverPeripheral
内我没有其他任何断点,但它永远不会被解雇。什么可能出错?我有所有必要的设置和代理