gpt4 book ai didi

ios - 似乎无法让核心蓝牙工作

转载 作者:行者123 更新时间:2023-11-28 22:38:42 25 4
gpt4 key购买 nike

我似乎无法在我的 iPad 上使用核心蓝牙。

ViewController.h

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

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 永远不会被记录,也永远不会检测到设备。我确保在我的设置中启用了蓝牙。

代码有什么问题?难道只是没有发现适用的设备?我可以在蓝牙设置中发现我的 iMac 一切正常。

此外,Core Bluetooth(在具有蓝牙 LE 的设备上运行)能否检测到非蓝牙 LE 设备?比如无线耳机?

最佳答案

Core Bluetooth 仅适用于低功耗蓝牙,您拥有的代码只会发现外围 BLE 设备,如 BLE 标签、心率监测器、传感器或 iOS 6 devices in peripheral mode .

所以不,您无法通过这种方式检测到您的 iMac(OS X 仍然没有通过 Core Bluetooth 的外围设备模式)或无线耳机。或者使用官方 SDK 的任何其他方式。

关于ios - 似乎无法让核心蓝牙工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15195322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com