Bluetooth 4.0 mio alpha watch 心率监护应用 2

刚鼓捣好第一个版本,比在android上开发ble简单多了,android主要是底层ble芯片不统一,ti的nordic的,所以没有官方的sdk,分别找htc或者三星的ae,他们会发给你sdk,但是大部分产品又没有ble,太乱了。

apple就标准了,

第一步 scan: startscanforUUID (heartrate 是0x180D),第一篇文章中提到ble的信息一直是广播的,和之前版本不一致,所以ios自己的系统里没有心率计也没关系;

第二步 connect: connect Peripherial;

第三步 找service: discoverService;

第四步 找characterist;

第五步 注册更新:

 

  
  
  
  
  1. [peripheral readValueForCharacteristic:aChar]; 
  2. [peripheral setNotifyValue:YES forCharacteristic:aChar]; 
  3. NSLog(@"Found a Heart Rate Measurement Characteristic"); 

 

该程序基于apple的core bluetooth framework (https://developer.apple.com/library/ios/#documentation/CoreBluetooth/Reference/CoreBluetooth_Framework/_index.html),参考了他的temperature 和 mac heart rate 的sample code,添加了disconnect和重新发现的功能,值得注意的地方是:

 

  
  
  
  
  1. service = [[[LeHeartRateNotificationService alloc] initWithPeripheral:peripheral controller:peripheralDelegate] autorelease]; 
  2. // 该代码在disconnect,再重新连接的时候有问题,需要手动释放service,并在clearDevices时候release 
  3.  
  4. service = [[LeHeartRateNotificationService alloc] initWithPeripheral:peripheral controller:peripheralDelegate]; 

 

 

代码还在更新中,如有需要,请联系我。

后续会发布到apple store, 大家可以测试下。

 

你可能感兴趣的:(apple,android,watch,4.0,BlueTooth,BLE,mio)