Iphone 仍然可以';t让CoreBooth在一个简单的名称发现应用程序中工作
我正在尝试制作一个简单的应用程序,它将扫描附近的蓝牙设备,并在发现它们时列出它们的名称。我使用的Iphone 仍然可以';t让CoreBooth在一个简单的名称发现应用程序中工作,iphone,ios,objective-c,xcode,bluetooth,Iphone,Ios,Objective C,Xcode,Bluetooth,我正在尝试制作一个简单的应用程序,它将扫描附近的蓝牙设备,并在发现它们时列出它们的名称。我使用的coreblutooth符合我找到的所有指南,包括苹果指南 然而,它从来都不起作用。我在运行应用程序的iPhone5旁边放了一个处于可发现模式的iPhone4S,但它从未发现。我也试过一辆支持蓝牙的车,但我不知道它是否有蓝牙功能。我做错了什么?以下是我在ViewController.m - (void)viewDidLoad { [super viewDidLoad]; [activi
coreblutooth
符合我找到的所有指南,包括苹果指南
然而,它从来都不起作用。我在运行应用程序的iPhone5旁边放了一个处于可发现模式的iPhone4S,但它从未发现。我也试过一辆支持蓝牙的车,但我不知道它是否有蓝牙功能。我做错了什么?以下是我在ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[activity stopAnimating]; isScanning = NO; //activity is a GUI activity wheel
centralManager = [[CBCentralManager alloc] initWithDelegate: self queue: nil];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
int state = central.state;
[self log: [NSString stringWithFormat: @"CBCentralManagerDidUpdateState: %d", state]];
//[self log] just NSLogs the message and adds it to a text view for the user to see.
if (state!=CBCentralManagerStatePoweredOn){
[self log: @"Error! Bluetooth not powered on!"]; //I never get this error.
}
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
[self log: [NSString stringWithFormat: @"Peripheral found with CoreBluetooth: %@", peripheral.name]];
//And I never see any of these "peripheral found" messages.
}
- (IBAction)scanButton:(id)sender {
if (!isScanning){
[activity startAnimating];
isScanning = YES;
[centralManager scanForPeripheralsWithServices:nil options:nil];
[self log: @"Scanning started."];
}
else{
[activity stopAnimating];
isScanning = NO;
[centralManager stopScan];
[self log: @"Scanning stopped."];
}
}
谢谢你的建议。我在这里找到了答案:
我需要一个外围模式的iOS设备或一个可扩展的外围设备。非常烦人,因为基本上没有外设使用BLE
它与我哥哥的iPhone4S一起工作,运行着一个来自应用商店LightBlue的免费应用程序。应用程序允许您将设备置于外围模式。。。开发人员推出这样一款不错的测试应用程序真是太好了