Ios didUpdateValueForCharacteristic(setNotifyValue:YES)不';行不通

Ios didUpdateValueForCharacteristic(setNotifyValue:YES)不';行不通,ios,bluetooth-lowenergy,core-bluetooth,Ios,Bluetooth Lowenergy,Core Bluetooth,我希望在值更改时收到通知。我正在学习本教程-> 我使用此蓝牙设备-> 控制台日志为: > 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 powe

我希望在值更改时收到通知。我正在学习本教程->

我使用此蓝牙设备->

控制台日志为:

> 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
>2014-03-23 21:37:37.215 CBTutorial[2736:60b]核心蓝牙[警告]未通电
2014-03-23 21:37:37.253 CBTutorial[2736:60b]蓝牙核心硬件已通电并准备就绪
2014-03-23 21:37:37.257发现CBTutorial[2736:60b]错误(null)
2014-03-23 21:37:37.261发现了CBTutorial[2736:60b](null)
2014-03-23 21:37:37.263 CBTutorial[2736:60b]找到了:PaSoRi
2014-03-23 21:37:37.493 CBTutorial[2736:60b]已连接:是
2014-03-23 21:37:37.726 CBTutorial[2736:60b]发现的服务:未知()
2014-03-23 21:37:37.728 CBTutorial[2736:60b]发现的服务:设备信息
2014-03-23 21:37:37.732 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.733 CBTutorial[2736:60b]值(空)
2014-03-23 21:37:37.735 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.736 CBTutorial[2736:60b]值
2014-03-23 21:37:37.738 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.739 CBTutorial[2736:60b]值(空)
2014-03-23 21:37:37.742 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.744 CBTutorial[2736:60b]值
2014-03-23 21:37:37.746 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.747 CBTutorial[2736:60b]值
2014-03-23 21:37:37.749 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.750 CBTutorial[2736:60b]值
2014-03-23 21:37:37.752 CBTutorial[2736:60b]发现特征:UUID:未知()
2014-03-23 21:37:37.753 CBTutorial[2736:60b]值
2014-03-23 21:37:37.756 CBTutorial[2736:60b]发现特征:UUID:制造商名称字符串
2014-03-23 21:37:37.758 CBTutorial[2736:60b]价值航空旅行社
2014-03-23 21:37:37.760 CBTutorial[2736:60b]发现特征:UUID:型号字符串
2014-03-23 21:37:37.762 CBTutorial[2736:60b]价值模型编号01
2014-03-23 21:37:37.764 CBTutorial[2736:60b]发现特征:UUID:固件修订字符串
2014-03-23 21:37:37.765 CBTutorial[2736:60b]价值固件01
2014-03-23 21:37:37.767 CBTutorial[2736:60b]发现特征:UUID:软件修订字符串
2014-03-23 21:37:37.768 CBTutorial[2736:60b]价值软件01
为什么我不能接收didUpdateValueForCharacteristic(甚至setNotifyValue:YES)回调?
(我已经试过触摸IC卡)请帮帮我。

首先。

在您的代码中,您正在调用:

_myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_myCentralManager scanForPeripheralsWithServices:nil options:nil];
在viewDidLoad中。这是一个错误。您应该调用
scanForPeripheralsWithServices:options:
进入
centralmanagerdipdatestate:
并且仅在
state==CBCentralManagerStatePoweredOn

秒:

将发现的外围设备分配给保留的
cbperipal
centralManager:didconnectperipal:
中是一种很好的做法,例如:

self.myPeripheral = peripheral;
self.myPeripheral.delegate = self;
第三

外围设备:didUpdateValueForCharacteristic:错误:
由以下人员调用:

  • readValueForCharacteristic:
  • setNotifyValue:forCharacteristic
为什么
readValueForCharacteristic:
没有调用
peripheral:didUpdateValueForCharacteristic:error:
,这真的很奇怪,也许还有一些额外的问题

你能试着调用
setNotifyValue:forCharacteristic
看看会发生什么吗


顺便说一句,最好的CoreBluetooth教程首先是Apple

在您的代码中,您正在调用:

_myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_myCentralManager scanForPeripheralsWithServices:nil options:nil];
在viewDidLoad中。这是一个错误。您应该调用
scanForPeripheralsWithServices:options:
进入
centralmanagerdipdatestate:
并且仅在
state==CBCentralManagerStatePoweredOn

秒:

将发现的外围设备分配给保留的
cbperipal
centralManager:didconnectperipal:
中是一种很好的做法,例如:

self.myPeripheral = peripheral;
self.myPeripheral.delegate = self;
第三

外围设备:didUpdateValueForCharacteristic:错误:
由以下人员调用:

  • readValueForCharacteristic:
  • setNotifyValue:forCharacteristic
为什么
readValueForCharacteristic:
没有调用
peripheral:didUpdateValueForCharacteristic:error:
,这真的很奇怪,也许还有一些额外的问题

你能试着调用
setNotifyValue:forCharacteristic
看看会发生什么吗


顺便说一句,最好的CoreBluetooth教程是Apple

首先,您需要将正确的命令写入固件,然后它会向您发送相应的响应。一旦从固件得到响应,就会调用didUpdateValueForCharacteristic方法。如果写操作不正确,您将不会得到任何响应,因此不会调用此方法


大多数情况下,我们将以十六进制形式发送命令。

首先,您需要将正确的命令写入固件,然后它将向您发送相应的响应。一旦从固件得到响应,就会调用didUpdateValueForCharacteristic方法。如果写操作不正确,您将不会得到任何响应,因此不会调用此方法


大多数情况下,我们将以十六进制形式发送命令。

从网页上看,索尼似乎提供了SDK并支持此产品,但它是付费产品:(您是否尝试过App store中的LightBlue应用程序?这是一个检查可编程外围设备的好工具,但您的代码看起来是正确的。在读者将数据返回给您之前,您可能需要向特征写入一些数据谢谢您的评论。SDK是一种付费产品。(以及 它只卖给公司