跳到主要内容

快速开始

5 步完成 SDK 接入,从安装到读取心率数据。

第 1 步:安装 SDK

Podfile 中添加:

source 'https://github.com/htangsmart/FitCloudPro-SDK-iOS.git'

platform :ios, '12.0'
use_frameworks!

target 'YourApp' do
# 基础模块(必需)
pod 'TopStepComKit-Git/Foundation'

# 通信模块
pod 'TopStepComKit-Git/ComKit'

# 设备实现模块
pod 'TopStepComKit-Git/FitCoreImp'

# 其他设备支持(按需添加)
# pod 'TopStepComKit-Git/FwCoreImp' # 未来支持
end

执行:

pod install

Info.plist 添加蓝牙权限:

<!-- iOS 13+ 必须 -->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>需要蓝牙权限以连接智能穿戴设备</string>

<!-- iOS 12 兼容 -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>需要蓝牙权限以连接智能穿戴设备</string>

第 2 步:初始化 SDK

AppDelegate.m 中:

#import <TopStepComKit/TopStepComKit.h>

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

TSKitConfigOptions *options = [TSKitConfigOptions configOptionWithSDKType:eTSSDKTypeFIT
license:@"YOUR_32_CHAR_LICENSE"];
options.isDevelopModel = YES; // 开发期间开启,上线前关闭

[[TopStepComKit sharedInstance] initSDKWithConfigOptions:options completion:^(BOOL isSuccess, NSError *error) {
if (isSuccess) {
TSLog(@"SDK 初始化成功");
}
}];

return YES;
}

第 3 步:搜索设备

id<TSBleConnectInterface> bleConnect = [TopStepComKit sharedInstance].bleConnector;

[bleConnect startSearchPeripheral:30
discoverPeripheral:^(TSPeripheral *peripheral) {
TSLog(@"发现设备: %@", peripheral.systemInfo.bleName);
[self.deviceList addObject:peripheral];
[self.tableView reloadData];
} completion:^(TSScanCompletionReason reason, NSError *error) {
TSLog(@"搜索结束,发现 %lu 台设备", (unsigned long)self.deviceList.count);
}];

第 4 步:连接设备

// 用户选择设备后停止扫描并连接
[bleConnect stopSearchPeripheral];

TSPeripheralConnectParam *param = [[TSPeripheralConnectParam alloc] initWithUserId:@"YOUR_USER_ID"];
param.authCode = @"qr_code_scanned_from_device"; // 首次绑定需要扫描设备二维码

[bleConnect connectWithPeripheral:selectedDevice
param:param
completion:^(TSBleConnectionState state, NSError *error) {
if (state == eTSBleStateConnected) {
TSLog(@"设备连接成功!");
[self onDeviceConnected];
} else if (error) {
TSLog(@"连接失败: %@", error.localizedDescription);
}
}];

第 5 步:同步健康数据

id<TSDataSyncInterface> dataSync = [TopStepComKit sharedInstance].dataSync;

// 从上次同步时间起,自动同步所有类型的健康数据
[dataSync syncDailyDataFromLastTime:^(NSArray<TSHealthData *> *results, NSError *error) {
if (error) {
TSLog(@"同步失败: %@", error.localizedDescription);
return;
}
for (TSHealthData *data in results) {
TSLog(@"数据类型: %ld,条数: %lu", (long)data.dataType, (unsigned long)data.healthValues.count);
}
}];

下一步