【发布时间】:2014-01-27 22:24:54
【问题描述】:
我想在 iOS 7 应用程序上扫描 ViewController 中的所有蓝牙设备,如下所示:
在 ViewController.h 中
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface ViewController : UIViewController <CBCentralManagerDelegate>
@property (strong, nonatomic) CBCentralManager *centralManager;
@end
在 ViewController.m 中
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - CBCentralManager Delegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (self.centralManager.state == CBCentralManagerStatePoweredOn)
{
NSLog(@"is on");
[self.centralManager scanForPeripheralsWithServices:nil options:nil];
}
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Discovered %@", peripheral.name);
}
我有日志消息“开启”但我没有结果,当我周围有几个时我发现没有蓝牙设备......为什么?
【问题讨论】:
-
它们是低功耗蓝牙吗?如果没有,您将不得不使用 ExternalAccessory.framework,因为 CoreBluetooth 仅适用于低功耗蓝牙。
-
是的,我认为.. 例如,我的 MacBook 是蓝牙 4.0
标签: ios bluetooth core-bluetooth