- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
据我们所知,iOS 6 支持运行设备(iPhone 4s 及以上,以及新的 iPad)作为 BLE 外设。 WWDC 2012 Session 705 中有一个名为“高级核心蓝牙”的演示。我向Apple要了源代码。他们向我发送了源代码的修改版本 (BTLE_Transfer_Draft)。然后我:
问题是根本没有发现外围设备。所以我使用其他测试应用程序,包括一些从 App Store 下载的应用程序。都没有发现外设。我认为问题应该出在BTLE_Transfer_Draft。因为我不确定是否允许我展示整个源代码。所以我在这里只展示“外设模式”部分:
- (void)viewDidLoad {
[super viewDidLoad];
// Start up the CBPeripheralManager
_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
}
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
// Opt out from any other state
if (peripheral.state != CBPeripheralManagerStatePoweredOn) {
return;
}
// We're in CBPeripheralManagerStatePoweredOn state...
NSLog(@"self.peripheralManager powered on.");
// ... so build our service.
// Start with the CBMutableCharacteristic
self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]
properties:CBCharacteristicPropertyNotify
value:nil
permissions:CBAttributePermissionsReadable];
// Then the service
CBMutableService *transferService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]
primary:YES];
// Add the characteristic to the service
transferService.characteristics = @[self.transferCharacteristic];
// And add it to the peripheral manager
[self.peripheralManager addService:transferService];
}
/** Start advertising
*/
- (IBAction)switchChanged:(id)sender
{
if (self.advertisingSwitch.on) {
// All we advertise is our service's UUID
[self.peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]] }];
}
else {
[self.peripheralManager stopAdvertising];
}
}
BLE处于开机状态,调用了startAdvertising。但是 BLE Central 永远无法发现它。
帖子更新:
根据 mttrb的建议我在开始广告时添加了“CBAdvertisementDataLocalNameKey”。但是我的服务仍然不能被大多数应用程序发现,包括来自应用程序商店的一些应用程序。唯一可以发现我的服务的应用是应用商店中名为“BLE 扫描仪”的应用。
我的问题是:这是否意味着我的应用程序正在作为外围设备运行?但是为什么我自己的代码发现不了服务呢?我该如何调试它?
我在中央模式下的代码是这样的:
- (void)viewDidLoad
{
[super viewDidLoad];
// Start up the CBCentralManager
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state != CBCentralManagerStatePoweredOn) {
return;
}
[self.centralManager scanForPeripheralsWithServices:nil options:nil];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
......
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
if (error) {
NSLog(@"Error discovering services: %@", [error localizedDescription]);
return;
}
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
// Deal with errors (if any)
if (error) {
NSLog(@"Error discovering characteristics: %@", [error localizedDescription]);
return;
}
}
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
NSLog(@"Peripheral Disconnected");
self.discoveredPeripheral = nil;
}
永远不会调用 didDiscoverPeripheral 和 didDiscoverServices。有什么问题吗?任何想法?谢谢
最佳答案
还有一个名为 LightBlue 的高质量免费应用程序你可以用它来测试你的代码。它应该能够在外围模式下接收所有广告设备,如果您想确保您的设备正常工作,它甚至可以将自己变成一个广告外围设备。
关于ios - 将 iOS 6 设备作为 BLE 外围设备运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13041930/
我有一个基于 Java 的应用程序 (Android),我希望能够在后台执行可能长时间的操作。 AsyncTask 上的 Android 文档建议不要将它们用于可能运行时间超过几秒的任务(这是为什么?
所以我有外围 BLE 设备,我需要一些标识符以便稍后与另一部 iPhone 共享。示例我将 iPhone 'A' 连接到外围设备。 iPhone 'A' 将外围设备的标识符保存到数据库中,稍后我可以轻
当我指定这样的服务时: centralManager.scanForPeripherals(withServices:[BEAN_SERVICE_UUID],选项:[CBCentralManagerS
我是一名优秀的程序员,十分优秀!