大佬教程收集整理的这篇文章主要介绍了将心率测量服务添加到iPhone作为外围设备,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要一些指导如何定义心率服务及其特征(在外围侧).
我还看到了使用特定服务UUID(180D)和UUID的一些特性(例如2A37用于心率测量,2A29用于制造商名称等)我从哪里获得这些数字?它们的定义在哪里?
如果需要任何其他信息请告知.
// Define the heart rate service CBMutableservice *heartRateservice = [[CBMutableservice alloc] initWithType:[CBUUID UUIDWithString:@"180D"] priMary:true]; // Define the sensor LOCATIOn characteristic char sensorLOCATIOn = 5; CBMutableCharacteristic *heartRateSensorLOCATIOnCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"0x2A38"] properties:CBCharacteristicPropertyRead value:[NSData dataWithBytesnoCopy:&sensorLOCATIOn length:1] permissions:CBAttributePermissionsReadable]; // Define the heart rate reading characteristic char heartRateData[2]; heartRateData[0] = 0; heartRateData[1] = 60; CBMutableCharacteristic *heartRateSensorHeartRateCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"2A37"] properties: CBCharacteristicPropertyNotify value:[NSData dataWithBytesnoCopy:&heartRateData length:2] permissions:CBAttributePermissionsReadable]; // Add the characteristics to the service heartRateservice.characteristics = @[heartRateSensorLOCATIOnCharacteristic,heartRateSensorHeartRateCharacteristic]; // Add the service to the peripheral manager [peripheralManager addservice:heartRateservice];
在此之后,您应该收到peripheralManager:didAddservice:error:表示添加成功的回调.您应该同样添加device information service (0x180A)最后,您应该开始做广告:
NSDictionary *data = @{ CBAdvertisementDataLocalNameKey:@"ideviceName",CBAdvertisementDataserviceUUIDsKey:@[[CBUUID UUIDWithString:@"180D"]]}; [peripheralManager startAdvertising:data];
注意:心率服务也是我实施的第一个.好的选择.
以上是大佬教程为你收集整理的将心率测量服务添加到iPhone作为外围设备全部内容,希望文章能够帮你解决将心率测量服务添加到iPhone作为外围设备所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。