首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoreBluetooth - writeValue。接收方无法从我的iPhone接收任何数据

CoreBluetooth - writeValue。接收方无法从我的iPhone接收任何数据
EN

Stack Overflow用户
提问于 2015-05-16 10:24:18
回答 1查看 620关注 0票数 0

这是一个与CoreBluetooth合作的项目。我使用我的iPhone 5c运行它。外设是单片机。iPhone可以接收来自单片机的数据。但是单片机不能通过[_peripheral writeValue:value forCharacteristic:_writeCharacteristic type:CBCharacteristicWriteWithResponse];接收来自iPhone的数据

以下是我的代码的一部分。

代码语言:javascript
复制
#define kServiceUUID @"FFE0"
#define kCharacteristicUUID @"FFE1"
#import "BTManager.h"

@interface BTManager()<CBCentralManagerDelegate, CBPeripheralDelegate>{
CBCentralManager *manager;
}

@property (strong,nonatomic) NSMutableArray *peripherals;
@property (nonatomic, strong) CBCharacteristic *writeCharacteristic;
@property (nonatomic, strong) CBPeripheral *peripheral;
@end

@implementation BTManager

#pragma mark - Public Methods

- (void)writeToPeripheral:(NSString *)dataString {
    if(_writeCharacteristic == nil){
        NSLog(@"writeCharacteristic is nil");
        return;
    }
    NSData *value = [self dataWithHexstring:dataString];
    NSLog(@"hex data:%@",value);
    [_peripheral writeValue:value forCharacteristic:_writeCharacteristic type:CBCharacteristicWriteWithResponse];
    NSLog(@"didWriteTo%@ characteristic:%@ data:%@",_peripheral.name,_writeCharacteristic.description,dataString);

}

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
    if (error) {
        NSLog(@"discoverCharacteristic:%@ Error:%@", service.UUID, [error localizedDescription]);
        return;
    }
    NSLog(@"Service:%@",service.UUID);
    for (CBCharacteristic *characteristic in service.characteristics) {
        if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:kCharacteristicUUID]]) {
            NSLog(@"setNotifyValuefor:%@",characteristic);
            _writeCharacteristic = characteristic;
            [self.peripheral setNotifyValue:YES forCharacteristic:characteristic];
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-05-18 22:08:38

我不认为你提供的源代码有任何问题。您尝试写入的特定外围设备是什么?

我想我会问的问题是

peripheral: didWriteValueForCharacteristic: error:中接收任何类型的响应的characteristic?

  • Are上是否确实支持writeWithResponse

如果你在上面提到的委托回调中没有看到响应,我会质疑外围设备是否正确地响应了写命令。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30271199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档