本文介绍了似乎无法获得蓝牙核心工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到核心蓝牙我的iPad的工作。

I can't seem to get core bluetooth working on my iPad.

ViewController.h

ViewController.h

@interface ViewController : UIViewController <CBCentralManagerDelegate, CBPeripheralDelegate>
{
    CBCentralManager *manager;
}
@end

ViewController.m

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UITextView *textField;

@end

@implementation ViewController

@synthesize textField;

- (void)viewDidLoad
{
    [super viewDidLoad];
    manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)action:(id)sender {
    textField.text = @"";

    if (manager.state == CBCentralManagerStatePoweredOn) {
        textField.text = @"Scanning...";
        NSLog(@"scanning");
        [manager scanForPeripheralsWithServices:nil options:nil];
    } else {
        textField.text = @"Error";
    }
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"2");
    textField.text = [NSString stringWithFormat:@"%@%@\n", textField.text, peripheral.name];
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    NSLog(@"d");
}

@end

2 永远不会被记录,并且从不检测设备。我确信,蓝牙是在我的设置中启用。

2 never gets logged and devices are never detected. I made sure that bluetooth is enabled in my settings.

什么是错的code?难道仅仅是因为没有适用的设备被发现的?我能发现我的iMac刚刚在蓝牙设置的罚款。

What's wrong with the code? Could it just be that no applicable devices are discovered? I can discover my iMac just fine in bluetooth settings.

另外,可以核心蓝牙(与蓝牙LE的设备上运行的)检测非蓝牙LE设备?诸如无线耳机

Also, can Core Bluetooth (running on a device with bluetooth LE) detect non bluetooth LE devices? Such as a wireless headset?

推荐答案

核心蓝牙只适用于低功耗蓝牙和code你只会发现外围BLE设备,如BLE标签,心脏速率监视器,传感器或iOS 6器件外设模式。

Core Bluetooth only works with Bluetooth Low Energy and the code you have will only discover peripheral BLE devices, like BLE tags, heart rate monitors, sensors or iOS 6 devices in peripheral mode.

所以,不,你不能检测到你的iMac(OS X仍然有通过Core蓝牙没有外设模式)或无线耳机这个样子。或其他任何方式与官方SDK。

So no, you can't detect your iMac (OS X still has no peripheral mode via Core Bluetooth) or wireless headset this way. Or any other way with official SDK.

这篇关于似乎无法获得蓝牙核心工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:47
查看更多