- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在值更改时收到通知。我正在关注本教程-> Introduction to Core Bluetooth: Building a Heart Rate Monitor
我使用此蓝牙设备-> IC card Reader (Sony product)
- (void)viewDidLoad {
[super viewDidLoad];
_myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_myCentralManager scanForPeripheralsWithServices:nil options:nil];
self.myCentralManager = _myCentralManager;
}
#pragma mark - CBCentralManagerDelegate
// method called whenever you have successfully connected to the BLE peripheral
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
[peripheral setDelegate:self];
[peripheral discoverServices:nil];
NSString *connected = [NSString stringWithFormat:@"Connected: %@", peripheral.state == CBPeripheralStateConnected ? @"YES" : @"NO"];
NSLog(@"%@", connected);
}
// CBCentralManagerDelegate - This is called with the CBPeripheral class as its main input parameter. This contains most of the information there is to know about a BLE peripheral.
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
NSLog(@"Discovered %@", _peripheral.name);
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
if ([localName length] > 0) {
NSLog(@"Found the : %@", localName);
// [self.myCentralManager stopScan];
self.peripheral = peripheral;
peripheral.delegate = self;
[self.myCentralManager connectPeripheral:peripheral options:nil];
}
}
// method called whenever the device state changes.
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
// Determine the state of the peripheral
if ([central state] == CBCentralManagerStatePoweredOff) {
NSLog(@"CoreBluetooth BLE hardware is powered off");
}
else if ([central state] == CBCentralManagerStatePoweredOn) {
NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
}
else if ([central state] == CBCentralManagerStateUnauthorized) {
NSLog(@"CoreBluetooth BLE state is unauthorized");
}
else if ([central state] == CBCentralManagerStateUnknown) {
NSLog(@"CoreBluetooth BLE state is unknown");
}
else if ([central state] == CBCentralManagerStateUnsupported) {
NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
#pragma mark - CBPeripheralDelegate
// CBPeripheralDelegate - Invoked when you discover the peripheral's available services.
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
for (CBService *service in peripheral.services) {
NSLog(@"Discovered service: %@", service.UUID);
[peripheral discoverCharacteristics:nil forService:service];
}
}
// Invoked when you discover the characteristics of a specified service.
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
// Deal with errors (if any)
if (error) {
NSLog(@"Error discovering characteristics: %@", [error localizedDescription]);
return;
}
// Again, we loop through the array, just in case.
for (CBCharacteristic *characteristic in service.characteristics) {
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
for (CBCharacteristic *aChar in service.characteristics)
{
[_peripheral setNotifyValue:YES forCharacteristic:aChar];
NSLog(@"Found characteristic : %@ UUID : %@",aChar.value,aChar.UUID);
NSString *value = [[NSString alloc] initWithData:aChar.value encoding:NSUTF8StringEncoding];
NSLog(@"Value %@",value);
}
}
// Invoked when you retrieve a specified characteristic's value, or when the peripheral device notifies your app that the characteristic's value has changed.
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
if (error) {
NSLog(@"Error reading characteristics: %@", [error localizedDescription]);
return;
}
if (characteristic.value != nil) {
//value here.
}
NSLog(@"Characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
//[delegate characteristicValueRead:characteristic.value];
NSLog(@"Caaled characteristic: %@",characteristic.value);
[self getHeartBPMData:characteristic error:error];
// Add your constructed device information to your UITextView
}
> 2014-03-23 21:37:37.215 CBTutorial[2736:60b] CoreBluetooth[WARNING] <CBCentralManager: 0x1455dec0> is not powered on
2014-03-23 21:37:37.253 CBTutorial[2736:60b] CoreBluetooth BLE hardware is powered on and ready
2014-03-23 21:37:37.257 CBTutorial[2736:60b] Discovered (null)
2014-03-23 21:37:37.261 CBTutorial[2736:60b] Discovered (null)
2014-03-23 21:37:37.263 CBTutorial[2736:60b] Found the : PaSoRi
2014-03-23 21:37:37.493 CBTutorial[2736:60b] Connected: YES
2014-03-23 21:37:37.726 CBTutorial[2736:60b] Discovered service: Unknown (<233e8100 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.728 CBTutorial[2736:60b] Discovered service: Device Information
2014-03-23 21:37:37.732 CBTutorial[2736:60b] Found characteristic : <0000ffff ff0200fe d7131600> UUID : Unknown (<233e8101 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.733 CBTutorial[2736:60b] Value (null)
2014-03-23 21:37:37.735 CBTutorial[2736:60b] Found characteristic : <000000> UUID : Unknown (<233e8102 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.736 CBTutorial[2736:60b] Value
2014-03-23 21:37:37.738 CBTutorial[2736:60b] Found characteristic : <0000ff00 ff00> UUID : Unknown (<233e8103 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.739 CBTutorial[2736:60b] Value (null)
2014-03-23 21:37:37.742 CBTutorial[2736:60b] Found characteristic : <> UUID : Unknown (<233e8104 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.744 CBTutorial[2736:60b] Value
2014-03-23 21:37:37.746 CBTutorial[2736:60b] Found characteristic : <> UUID : Unknown (<233e8105 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.747 CBTutorial[2736:60b] Value
2014-03-23 21:37:37.749 CBTutorial[2736:60b] Found characteristic : <> UUID : Unknown (<233e8106 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.750 CBTutorial[2736:60b] Value
2014-03-23 21:37:37.752 CBTutorial[2736:60b] Found characteristic : <> UUID : Unknown (<233e8107 3a1b1c59 9bee1803 73dd03a1>)
2014-03-23 21:37:37.753 CBTutorial[2736:60b] Value
2014-03-23 21:37:37.756 CBTutorial[2736:60b] Found characteristic : <41697250 61536f52 69> UUID : Manufacturer Name String
2014-03-23 21:37:37.758 CBTutorial[2736:60b] Value AirPaSoRi
2014-03-23 21:37:37.760 CBTutorial[2736:60b] Found characteristic : <4d6f6465 6c4e756d 62657230 31> UUID : Model Number String
2014-03-23 21:37:37.762 CBTutorial[2736:60b] Value ModelNumber01
2014-03-23 21:37:37.764 CBTutorial[2736:60b] Found characteristic : <4669726d 77617265 3031> UUID : Firmware Revision String
2014-03-23 21:37:37.765 CBTutorial[2736:60b] Value Firmware01
2014-03-23 21:37:37.767 CBTutorial[2736:60b] Found characteristic : <536f6674 77617265 3031> UUID : Software Revision String
2014-03-23 21:37:37.768 CBTutorial[2736:60b] Value Software01
最佳答案
首先。
在您的代码中,您正在调用:
_myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_myCentralManager scanForPeripheralsWithServices:nil options:nil];
scanForPeripheralsWithServices:options:
的情况下将
centralManagerDidUpdateState:
称为
state == CBCentralManagerStatePoweredOn
CBPeripheral
到
centralManager: didConnectPeripheral:
中,例如:
self.myPeripheral = peripheral;
self.myPeripheral.delegate = self;
peripheral: didUpdateValueForCharacteristic: error:
通过以下方式调用:
readValueForCharacteristic:
setNotifyValue: forCharacteristic
readValueForCharacteristic:
不调用
peripheral: didUpdateValueForCharacteristic: error:
真的很奇怪,也许还有一些额外的问题。
setNotifyValue: forCharacteristic
看看会发生什么吗?
关于ios - didUpdateValueForCharacteristic(setNotifyValue:YES)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22591352/
这个问题在这里已经有了答案: NSNumber Literals (5 个答案) 关闭 6 年前。 我正在发出一个 HTTP 请求,我必须在其中发送一个 bool 值。我试过他们两个。 两者的工作方
我使用 FireBug 测试了这两种情况,结果看起来非常相似: >>> var x = {"active": "yes"} >>> x.active "yes" >>> var x = {active
在 Objective-c 中,@YES/@NO 和 YES/NO 有什么区别?每种类型使用什么类型? 最佳答案 @YES 是 [NSNumber numberWithBool:YES] 的缩写形式
我正在编写一个脚本来创建虚拟机,显然我想支持标准的确认/whatif 语义。但是,如果我要创建多台机器,最好能区分"is"和“全部是”,这样我就不必重新确认每台机器。 $pscmdlet.Should
这个问题在这里已经有了答案: In JavaScript, why is "0" equal to false, but when tested by 'if' it is not false by
我需要编写一个正则表达式来验证字符串。如果正则表达式包含以下任何内容,则应传递字符串:y、Y、yes、YES , 1。这些字母可以是任何大小写。我是正则表达式和 JavaScript 的新手。 最佳答
我是网络开发的新手,如果能得到任何帮助,我将不胜感激。我有一个 HTML/CSS slider ,当 slider 处于"is"位置(如名字和主题)时,我想显示更多的文本框字段。如果可能的话,我真的希
bash: $: yes a [some output] then press Ctrl+Z $: yes b [some output] then press Ctrl+Z 然后,执行两
我感兴趣的是能够在 Yes/No 提示符下自动让我的 cmd 输入 Yes: __
以上说明了一切-我将 UITextField 设置为安全,但希望为用户提供使其不安全的选项(因此,如果他们在私有(private)区域中,他们可以确定输入的内容)。但是,假设他们误按了切换开关,并想将
当 ssh hostname 提示 The authenticity of host 'foobar' can't be established. ECDSA key fingerprint is .
如何在自定义 MKAnnotationView 上正确设置半径并允许标注?这会引发异常: 来 self 的自定义 MKAnnotationView 类: - (id)initWithFrame:(CG
如果我有 1200 行,并且我希望我的 120 行说"is"而其余的说“否”,我应该如何将其应用于 Excel 文件?我知道使用: =CHOOSE(RANDBETWEEN(1,2),"Yes","No
我想进行一个查询,返回如下所示的表结果: 列标题是我的一个表格中的字段,下面的数字是该字段的是/否条目数。 我遇到的问题是在行的开头显示是/否。我希望它以这种方式组织,以便更好地根据数据创建图表。 现
这个问题在这里已经有了答案: Literal @YES not working in iOS 5 / Xcode 4.4 (2 个答案) 关闭 7 年前。 使用 XCode 4.4 的 Conver
这段代码: $query = array( "var" => "no", "not_var" => "yes", "var2" => "maybe" ); print http
在我的 Dynamics CRM 机会表单中,我添加了销售配额分配网格。如果在整个网格中输入了四个以上"is",我希望显示一条警告消息(或类似的内容)。例如,假设记录“A”t 有 4 个标记为"is"
This question already has answers here: How do I perform an IF…THEN in an SQL SELECT? (31个答案) 已关闭6年。
考虑以下文档: foo: bar: Yes 根据the spec,这应该解释为Boolean,而不是String。 但是,it seems对此文档产生了相同的解释: foo: bar: 'Ye
在网页的第一页上,它要求用户从下拉列表中选择他们想要的产品类型,并且为每个产品指定一个值 0,1,2...然后,一旦他们继续,他们就会被发送到不同的网页,并根据他们选择的产品在那里我希望单选按钮自动选
我是一名优秀的程序员,十分优秀!