VScale SDK iOS 集成说明
1. 将 VScale 文件夹添加到您的工程中,如下图所示。
2. 使用 CocoaPods 安装 FMDB,编辑 Podfile,增加如下行,
pod 'FMDB'
3. 在工程中链接 libsqlite3.0.tbd,选中工程 target, 在 General -> Linked Frameworks and Libraries 列表中进行添加,如下图所示。
4. 在 Build Setting,在“Other Linker Flags”中加入“-Objc”,(如下图所示)。
5. 在 Capabilities,打开 Background Modes,并勾选 Use Bluetooth LE accessories 和 Acts as a Bluetooth LE accessory。如下图所示。
6. 配置 VTDeviceManager,如下所示。
#import “VTScales.h"
// 设置key
[VTDeviceManager sharedInstance].key = @“XXXXXXXXXXXXXXX";
// 设置用户信息,用户信息以json字符串格式写入蓝牙库。
NSDictionary *dict = @{@"age": @(40), @"height": @(160), @"gender": @(0)};
NSString *string = [self createStringFromDict:dict];
[[VTDeviceManager sharedInstance] setUserJSONString:string];
- (NSString *)createStringFromDict:(NSDictionary *)dict
{
NSData *data = [NSData dataWithData:[NSJSONSerialization dataWithJSONObject:dict options:0 error:nil]];
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
// 设置代理,接收蓝牙库回调
[VTDeviceManager sharedInstance].delegate = self;
// 开始扫描
[[VTDeviceManager sharedInstance] scanWithType:VT_DEVICE_MODEL_VSCALE lockFirstDiscoveredProtocol:false];
//实现代理方法
#pragma mark - VTDeviceManagerDelegate
- (void)deviceManager:(VTDeviceManager *)dm didDiscoverAdvertiseScaleWithJSONString:(NSString *)JSONString
{
NSLog(@"%s %d %@", __func__, __LINE__, JSONString);
}
7. VTDeviceManagerDelegate 方法 - (void)deviceManager:(VTDeviceManager *)dm didDiscoverAdvertiseScaleWithJSONString:(NSString *)JSONString 的参数 JSONString 为 JSON 字符串,包含了动态体重数据或体脂数据。如下所示,code 为 200 表示动态体重数据,code 为 0 表示体脂数据。
动态体重数据
{“details”:{“weight”:43},”msg”:”success","code":200,"sn":"xxxxxxxxxx"}
体脂数据
{
"code": 0,
"details": {
"ageOfBody": 33,
"bmi": 16.4,
"bmr": 1297,
"bodyShape": 8,
"desirableWeight": 62.0,
"fatFreeBodyWeight": 40.5,
"fatToControl": 0.0,
"idealWeight": 55.0,
"levelOfVisceralFat": 2,
"muscleToControl": 7.4,
"obesityLevel": 0,
"rateOfBurnFat": {
"max": 144,
"min": 108
},
"ratioOfFat": 3.5,
"ratioOfMuscle": 42.7,
"ratioOfProtein": 27.8,
"ratioOfSubcutaneousFat": 3.3,
"ratioOfWater": 69.4,
"score": 48.1,
"stateOfNutrition": 2,
"weight": 42.0,
"weightOfBone": 1.9,
"weightOfFat": 1.5,
"weightOfMuscle": 17.9,
"weightOfProtein": -10000,
"weightOfSkeletalMuscle": 12.7,
"weightOfWater": 29.1,
"weightToControl": -20.0,
“sn":"xxxxxxxxxx"
},
"msg": "success"
}
网友评论