Skip to main content

BleConnect

The BleConnect module provides comprehensive Bluetooth Low Energy (BLE) device management capabilities, including device discovery, connection, authentication, and binding. It handles the complete connection lifecycle from initial scanning through authentication to full readiness, with granular state tracking and error handling at each stage.

Prerequisites

  • iOS 12.0 or later
  • Bluetooth Low Energy (BLE) capable device
  • NSBluetoothPeripheralUsageDescription permission in Info.plist
  • NSBluetoothCentralUsageDescription permission in Info.plist
  • User must grant Bluetooth permissions at runtime

Data Models

TSPeripheral

Complete peripheral device information container.

PropertyTypeDescription
systemInfoTSPeripheralSystem *System-level information including Bluetooth connection details, MAC address, and device identification
screenInfoTSPeripheralScreen *Screen properties including size, shape, border radius, and preview dimensions
projectInfoTSPeripheralProject *Project-level information including firmware version, serial number, and device identifiers
capabilityTSPeripheralCapability *Device capability information including supported features and functionalities
limitationTSPeripheralLimitations *Device feature limitations including maximum counts for alarms, reminders, and contacts

TSPeripheralSystem

System-level information for peripheral devices.

PropertyTypeDescription
peripheralCBPeripheral *Core Bluetooth peripheral object for device communication
centralCBCentralManager *Bluetooth central manager controlling connections and scanning
uuidNSString *UUID string from CBPeripheral.identifier (read-only)
macNSString *Device MAC address in colon-separated format (e.g., "DE:82:47:15:28:B0")
bleNameNSString *Device Bluetooth name broadcasted for user identification
RSSINSNumber *Bluetooth signal strength indicator (RSSI value)
advertisementDataNSDictionary *Raw advertisement data dictionary containing service UUIDs and manufacturer data

TSPeripheralProject

Project-related information for peripheral devices.

PropertyTypeDescription
projectIdNSString *Unique identifier for the project type
companyIdNSString *Company identifier from BLE manufacturer data (typically 4-character hex string)
brandNSString *Device brand name (maximum 16 characters)
modelNSString *Device model identifier (maximum 16 characters)
firmVersionNSString *Current firmware version (semantic versioning format)
virtualVersionNSString *Special version number for internal version control
serialNumberNSString *Unique device serial number
mainProjNumNSString *Main project number used in FitCloudKit
subProjNumNSString *Sub project number for variant identification

TSPeripheralScreen

Screen information for peripheral devices.

PropertyTypeDescription
shapeTSPeriphShapeDevice physical shape (circle, square, vertical rectangle, horizontal rectangle)
screenSizeCGSizeScreen size in pixels
screenBorderRadiusCGFloatScreen border radius in pixels
dialPreviewSizeCGSizeWatch face preview image size in pixels
dialPreviewBorderRadiusCGFloatWatch face preview image corner radius in pixels
videoPreviewSizeCGSizeVideo preview stream size in pixels
videoPreviewBorderRadiusCGFloatVideo preview stream corner radius in pixels

TSPeripheralCapability

Device capability container organizing feature support into distinct modules.

PropertyTypeDescription
featureAbilityTSFeatureAbility *Coarse-grained feature module support flags (YES/NO)
messageAbilityTSMessageAbility *Fine-grained message type support details (which types supported)
dailyActivityAbilityTSDailyActivityAbility *Fine-grained daily activity type support (which types supported)
sleepAlgorithmNSIntegerDevice sleep algorithm type (0=LongestNight, 1=LongestOnly)

TSFeatureAbility

Feature module capability flags indicating which major features are supported.

PropertyTypeDescription
originAbilityNSData *Raw ability data from device (maximum 16 bytes)
supportCapabilitiesTSPeripheralSupportAbilityParsed capability flags indicating supported features
isSupportStepCountingBOOLStep counting support
isSupportDistanceCountingBOOLDistance counting support
isSupportCalorieCountingBOOLCalorie counting support
isSupportHeartRateBOOLHeart rate monitoring support
isSupportBloodPressureBOOLBlood pressure monitoring support
isSupportBloodOxygenBOOLBlood oxygen monitoring support
isSupportStressBOOLStress monitoring support
isSupportSleepBOOLSleep monitoring support
isSupportTemperatureBOOLTemperature monitoring support
isSupportECGBOOLECG monitoring support
isSupportFemaleHealthBOOLFemale health features support
isSupportInitiateWorkoutBOOLInitiate workout feature support
isSupportWeightManagementBOOLWeight management support
isSupportRemindersBOOLReminders support
isSupportCallManagementBOOLCall management support
isSupportAppNotificationsBOOLApp notifications support
isSupportMusicControlBOOLMusic control support
isSupportWeatherDisplayBOOLWeather display support
isSupportFindMyPhoneBOOLFind my phone feature support
isSupportAlarmClockBOOLAlarm clock support
isSupportWorldClockBOOLWorld clock support
isSupportMapNavigationBOOLMap navigation support
isSupportShakeCameraBOOLShake to take photo support
isSupportCameraPreviewBOOLCamera video preview support
isSupportEWalletBOOLE-wallet support
isSupportBusinessCardBOOLBusiness card support
isSupportPhotoAlbumBOOLPhoto album support
isSupportEBookBOOLE-book support
isSupportVoiceRecordingBOOLVoice recording support
isSupportAppStoreBOOLApp store support
isSupportMotionGamesBOOLMotion sensing games support
isSupportSportUploadBOOLSport upload support
isSupportERNIEBotBOOLERNIE Bot support
isSupportChatGPTBOOLChatGPT support
isSupportLoversFeatureBOOLLovers feature support
isSupportContactsBOOLContacts feature support
isSupportEmergencyContactsBOOLEmergency contacts support
isSupportMuslimPrayerBOOLMuslim prayer reminders support
isSupportQiblaCompassBOOLQibla compass support
isSupportNFCPaymentBOOLNFC payment support
isSupportVoiceAssistantBOOLVoice assistant support
isSupportFacePushBOOLWatch face push support
isSupportCustomFaceBOOLCustom watch face support
isSupportSlideshowFaceBOOLSlideshow watch face support
isSupportDialComponentBOOLDial component support
isSupportTimeSettingsBOOLTime settings support
isSupportLanguageBOOLLanguage settings support
isSupportUserInfoSettingsBOOLUser information settings support
isSupportDailyActivityBOOLDaily activity support
isSupportFirmwareUpgradeBOOLFirmware upgrade support
isSupportUnitSettingsBOOLUnit settings support
isSupportEarbudsAPIsBOOLEarbuds APIs support
isSupportAIChatBOOLAI chat support
isSupportAIChatAudioUsingScoBOOLAI chat audio using SCO support
isSupportScreenLockBOOLScreen lock support
isSupportGameLockBOOLGame lock support

TSMessageAbility

Message notification ability managing which specific message types are supported.

PropertyTypeDescription
(No public properties)-All data is encapsulated; use query methods to check support

TSDailyActivityAbility

Daily activity ability managing which activity types are supported and displayed.

PropertyTypeDescription
(No public properties)-All data is encapsulated; use query methods to check support

TSPeripheralConnectParam

Connection parameters for device connection and binding.

PropertyTypeDescription
userIdNSString *User ID for device connection (required, must not be empty)
userInfoTSUserInfoModel *User information model for device personalization
authCodeNSString *Authentication code from QR code scanning during binding
allowConnectWithBTBOOLFlag indicating whether Bluetooth connection is allowed
brandNSString *Phone brand information (e.g., "Apple", "Samsung")
modelNSString *Phone model information (e.g., "iPhone 12", "iPhone 13 Pro")
systemVersionNSString *Phone system version (e.g., "iOS 15.0")

TSPeripheralScanParam

Advanced scan parameters for device discovery.

PropertyTypeDescription
userIdNSString *User ID for device connection
serviceUUIDsNSArray<CBUUID *> *Service UUIDs to filter peripherals (nil to discover all)
solicitedServiceUUIDsNSArray<CBUUID *> *Solicited service UUIDs filter (nil to not filter)
deviceNameNSString *Device name filter (nil to discover all)
macAddressNSString *MAC address filter (nil to discover all)
onlyUnconnectedBOOLOnly return unconnected peripherals (default NO)
allowDuplicatesBOOLAllow duplicate discovery of same peripheral (default NO)
scanTimeoutNSIntegerScan timeout in seconds (0 = no timeout)

TSPeripheralLimitations

Device feature limitations defining hardware and firmware constraints.

PropertyTypeDescription
maxAlarmCountUInt8Maximum number of alarm clocks (0 = not supported)
maxContactCountUInt8Maximum number of contacts (0 = not supported)
maxEmergencyContactCountUInt8Maximum number of emergency contacts (0 = not supported, 255 = unlimited)
maxPushDialCountUInt8Maximum number of custom watch face slots (0 = not supported)
maxInnerDialCountUInt8Number of pre-installed watch faces
maxWorldClockCountUInt8Maximum number of world clocks (0 = not supported, 255 = unlimited)
maxSedentaryReminderCountUInt8Maximum number of sedentary reminders (0 = not supported, 255 = unlimited)
maxWaterDrinkingReminderCountUInt8Maximum number of water drinking reminders (0 = not supported, 255 = unlimited)
maxMedicationReminderCountUInt8Maximum number of medication reminders (0 = not supported, 255 = unlimited)
maxCustomReminderCountUInt8Maximum number of custom reminders (0 = not supported, 255 = unlimited)

TSBluetoothSystem

Complete Bluetooth system information including both BLE and Classic Bluetooth.

PropertyTypeDescription
bleInfoTSBluetoothInfo *BLE (Bluetooth Low Energy) adapter information
btInfoTSBluetoothInfo *BT (Classic Bluetooth) adapter information

TSBluetoothInfo

Bluetooth adapter information model.

PropertyTypeDescription
macAddressNSString *Bluetooth MAC address in colon-separated format (may be nil on iOS)
nameNSString *Bluetooth adapter name
statusTSBleStatusBluetooth adapter connection status

Enumerations

TSBleConnectionState

Bluetooth connection state during the connection lifecycle.

ValueNameDescription
0eTSBleStateDisconnectedNot connected (initial state or after any failure)
1eTSBleStateConnectingEstablishing BLE physical connection
2eTSBleStateAuthenticatingPerforming bind/login authentication
3eTSBleStatePreparingDataFetching device information after authentication
4eTSBleStateConnectedConnected and ready for data operations

TSScanCompletionReason

Reasons why BLE scanning completes.

ValueNameDescription
1000eTSScanCompleteReasonTimeoutScan timeout reached
1001eTSScanCompleteReasonBleNotReadyBluetooth not ready
1002eTSScanCompleteReasonPermissionDeniedBluetooth permissions denied
1003eTSScanCompleteReasonUserStoppedUser manually stopped scan
1004eTSScanCompleteReasonSystemErrorSystem error occurred
1005eTSScanCompleteReasonNotSupportBluetooth not supported

TSBleStatus

Bluetooth adapter connection status.

ValueNameDescription
0TSBleDisconnectedNot connected
1TSBleConnectedConnected (physical connection established)
2TSBleReadyReady (connected and Notify/SPP opened)

TSPeriphShape

Device physical shape characteristics.

ValueNameDescription
0eTSPeriphShapeUnknowUnknown shape
1eTSPeriphShapeCircleCircular device
2eTSPeriphShapeSquareSquare device
3eTSPeriphShapeVerticalRectangleVertical rectangle device
4eTSPeriphShapeTransverseRectangleHorizontal rectangle device

TSPeripheralSupportAbility

Bit flags indicating peripheral feature support (uint64_t).

Bit RangeCategoryFlags
0-15Health FeaturesTSPeripheralSupportStepCounting, TSPeripheralSupportDistanceCounting, TSPeripheralSupportCalorieCounting, TSPeripheralSupportHeartRate, TSPeripheralSupportBloodPressure, TSPeripheralSupportBloodOxygen, TSPeripheralSupportStress, TSPeripheralSupportSleep, TSPeripheralSupportTemperature, TSPeripheralSupportECG, TSPeripheralSupportFemaleHealth, TSPeripheralSupportInitiateWorkout, TSPeripheralSupportDailyActivity, TSPeripheralSupportWeightManagement
16-33Smart FeaturesTSPeripheralSupportReminders, TSPeripheralSupportCallManagement, TSPeripheralSupportAppNotifications, TSPeripheralSupportMusicControl, TSPeripheralSupportWeatherDisplay, TSPeripheralSupportFindMyPhone, TSPeripheralSupportAlarmClock, TSPeripheralSupportWorldClock, TSPeripheralSupportMapNavigation, TSPeripheralSupportShakeCamera, TSPeripheralSupportCameraPreview, TSPeripheralSupportEWallet, TSPeripheralSupportBusinessCard, TSPeripheralSupportPhotoAlbum, TSPeripheralSupportEBook, TSPeripheralSupportVoiceRecording, TSPeripheralSupportAppStore, TSPeripheralSupportMotionGames
34-36AI FeaturesTSPeripheralSupportSportUpload, TSPeripheralSupportERNIEBot, TSPeripheralSupportChatGPT
37-39Social FeaturesTSPeripheralSupportLoversFeature, TSPeripheralSupportContacts, TSPeripheralSupportEmergencyContacts
40-41Religious FeaturesTSPeripheralSupportMuslimPrayer, TSPeripheralSupportQiblaCompass
42-46Hardware FeaturesTSPeripheralSupportNFCPayment, TSPeripheralSupportVoiceAssistant, TSPeripheralSupportFacePush, TSPeripheralSupportCustomFace, TSPeripheralSupportSlideshowFace
47-51System SettingsTSPeripheralSupportTimeSettings, TSPeripheralSupportLanguageSettings, TSPeripheralSupportUserInfoSettings, TSPeripheralSupportFirmwareUpgrade, TSPeripheralSupportUnitSettings
52-63ReservedTSPeripheralSupportEarbudsAPIs, TSPeripheralSupportDialComponent, TSPeripheralSupportAIChat, TSPeripheralSupportAIChatAudioUsingSco, TSPeripheralSupportScreenLock, TSPeripheralSupportGameLock

Callback Types

TSScanDiscoveryBlock

Device discovery callback during scanning.

typedef void(^TSScanDiscoveryBlock)(TSPeripheral *_Nonnull peripheral);
ParameterTypeDescription
peripheralTSPeripheral *Discovered peripheral with device name, ID, and other information

TSScanCompletionBlock

Scan completion callback.

typedef void(^TSScanCompletionBlock)(TSScanCompletionReason reason, NSError * _Nullable error);
ParameterTypeDescription
reasonTSScanCompletionReasonReason for scan completion (timeout, user stopped, error, etc.)
errorNSError *Optional error details if scan failed

TSBleConnectionStateCallback

Bluetooth connection state change callback.

typedef void (^TSBleConnectionStateCallback)(TSBleConnectionState connectionState);
ParameterTypeDescription
connectionStateTSBleConnectionStateCurrent connection state during the connection lifecycle

TSBleConnectionCompletionBlock

Bluetooth connection completion callback.

typedef void (^TSBleConnectionCompletionBlock)(TSBleConnectionState connectionState, NSError *_Nullable error);
ParameterTypeDescription
connectionStateTSBleConnectionStateFinal connection state (eTSBleStateConnected on success, eTSBleStateDisconnected on failure)
errorNSError *Optional error details if connection failed

API Reference

Get current Bluetooth connection state

- (void)getConnectState:(TSBleConnectionStateCallback)completion;
ParameterTypeDescription
completionTSBleConnectionStateCallbackCallback returning current connection state

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

[bleConnect getConnectState:^(TSBleConnectionState connectionState) {
switch (connectionState) {
case eTSBleStateDisconnected:
TSLog(@"Device is not connected");
break;
case eTSBleStateConnecting:
TSLog(@"Device is connecting");
break;
case eTSBleStateAuthenticating:
TSLog(@"Device is authenticating");
break;
case eTSBleStatePreparingData:
TSLog(@"Device is preparing data");
break;
case eTSBleStateConnected:
TSLog(@"Device is connected and ready");
break;
}
}];

Start searching for Bluetooth devices

- (void)startSearchPeripheral:(NSTimeInterval)timeout
discoverPeripheral:(TSScanDiscoveryBlock)discoverPeripheral
completion:(TSScanCompletionBlock)completion;
ParameterTypeDescription
timeoutNSTimeIntervalScan timeout in seconds (0 = default 30 seconds)
discoverPeripheralTSScanDiscoveryBlockCallback triggered when a new device is discovered
completionTSScanCompletionBlockCallback when scan completes or times out

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

[bleConnect startSearchPeripheral:30.0
discoverPeripheral:^(TSPeripheral *peripheral) {
TSLog(@"Found device: %@", peripheral.systemInfo.bleName);
TSLog(@"MAC: %@", peripheral.systemInfo.mac);
TSLog(@"RSSI: %@", peripheral.systemInfo.RSSI);
} completion:^(TSScanCompletionReason reason, NSError *error) {
if (error) {
TSLog(@"Scan failed with error: %@", error.localizedDescription);
} else {
switch (reason) {
case eTSScanCompleteReasonTimeout:
TSLog(@"Scan timeout");
break;
case eTSScanCompleteReasonUserStopped:
TSLog(@"Scan stopped by user");
break;
default:
TSLog(@"Scan completed with reason: %ld", (long)reason);
}
}
}];

Start searching with advanced parameters

- (void)startSearchPeripheralWithParam:(TSPeripheralScanParam *)param
discoverPeripheral:(TSScanDiscoveryBlock)discoverPeripheral
completion:(TSScanCompletionBlock)completion;
ParameterTypeDescription
paramTSPeripheralScanParam *Scan parameters including filters and timeout
discoverPeripheralTSScanDiscoveryBlockCallback triggered when a new device is discovered
completionTSScanCompletionBlockCallback when scan completes with reason and optional error

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

TSPeripheralScanParam *scanParam = [[TSPeripheralScanParam alloc] init];
scanParam.userId = @"user123";
scanParam.deviceName = @"MyDevice";
scanParam.scanTimeout = 30;
scanParam.allowDuplicates = YES;

[bleConnect startSearchPeripheralWithParam:scanParam
discoverPeripheral:^(TSPeripheral *peripheral) {
TSLog(@"Found device: %@", peripheral.systemInfo.bleName);
} completion:^(TSScanCompletionReason reason, NSError *error) {
if (error) {
TSLog(@"Scan error: %@", error.localizedDescription);
} else {
TSLog(@"Scan completed with reason: %ld", (long)reason);
}
}];

Stop searching for Bluetooth devices

- (void)stopSearchPeripheral;

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

[bleConnect stopSearchPeripheral];
TSLog(@"Scan stopped");

Connect to a Bluetooth device

- (void)connectWithPeripheral:(TSPeripheral *)peripheral
param:(TSPeripheralConnectParam *)param
completion:(TSBleConnectionCompletionBlock)completion;
ParameterTypeDescription
peripheralTSPeripheral *Peripheral device to connect to
paramTSPeripheralConnectParam *Connection parameters with binding info including user ID
completionTSBleConnectionCompletionBlockCallback for connection result with state and optional error

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;
TSPeripheral *peripheral = /* discovered peripheral */;

TSPeripheralConnectParam *connectParam = [[TSPeripheralConnectParam alloc] initWithUserId:@"user123"];
connectParam.authCode = @"ABC123";
connectParam.brand = @"Apple";
connectParam.model = @"iPhone 15";
connectParam.systemVersion = @"17.0";

[bleConnect connectWithPeripheral:peripheral
param:connectParam
completion:^(TSBleConnectionState connectionState, NSError *error) {
if (error) {
TSLog(@"Connection failed: %@", error.localizedDescription);
return;
}

switch (connectionState) {
case eTSBleStateConnecting:
TSLog(@"Connecting to device...");
break;
case eTSBleStateAuthenticating:
TSLog(@"Authenticating with device...");
break;
case eTSBleStatePreparingData:
TSLog(@"Preparing device data...");
break;
case eTSBleStateConnected:
TSLog(@"Device connected successfully!");
break;
case eTSBleStateDisconnected:
TSLog(@"Connection failed");
break;
}
}];

Reconnect to a previously bound device

- (void)reconnectWithPeripheral:(TSPeripheral *)peripheral
param:(TSPeripheralConnectParam *)param
completion:(TSBleConnectionCompletionBlock)completion;
ParameterTypeDescription
peripheralTSPeripheral *Peripheral device to reconnect to
paramTSPeripheralConnectParam *Connection parameters with same user ID as original binding
completionTSBleConnectionCompletionBlockCallback for reconnection result with state and optional error

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;
TSPeripheral *peripheral = /* previously bound peripheral */;

TSPeripheralConnectParam *reconnectParam = [[TSPeripheralConnectParam alloc] initWithUserId:@"user123"];
reconnectParam.brand = @"Apple";
reconnectParam.model = @"iPhone 15";
reconnectParam.systemVersion = @"17.0";

[bleConnect reconnectWithPeripheral:peripheral
param:reconnectParam
completion:^(TSBleConnectionState connectionState, NSError *error) {
if (error) {
TSLog(@"Reconnection failed: %@", error.localizedDescription);
return;
}

if (connectionState == eTSBleStateConnected) {
TSLog(@"Device reconnected successfully!");
}
}];

Disconnect from the currently connected device

- (void)disconnectCompletion:(TSCompletionBlock)completion;
ParameterTypeDescription
completionTSCompletionBlockCallback that returns disconnection result

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

[bleConnect disconnectCompletion:^(NSError *error) {
if (error) {
TSLog(@"Disconnect failed: %@", error.localizedDescription);
} else {
TSLog(@"Device disconnected successfully");
}
}];

Unbind the currently connected device

- (void)unbindPeripheralCompletion:(TSCompletionBlock)completion;
ParameterTypeDescription
completionTSCompletionBlockCallback that returns unbinding result

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

[bleConnect unbindPeripheralCompletion:^(NSError *error) {
if (error) {
TSLog(@"Unbind failed: %@", error.localizedDescription);
} else {
TSLog(@"Device unbound successfully");
}
}];

Check if a device is currently connected

- (BOOL)isConnected;

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

if ([bleConnect isConnected]) {
TSLog(@"Device is connected");
} else {
TSLog(@"Device is not connected");
}

Get Bluetooth adapter information

- (void)getBluetoothInfo:(void(^)(TSBluetoothSystem * _Nullable bluetoothInfo, NSError * _Nullable error))completion;
ParameterTypeDescription
completionvoid(^)(TSBluetoothSystem *, NSError *)Callback returning Bluetooth system information including BLE and BT adapter details

Code Example:

id<TSBleConnectInterface> bleConnect = /* obtained from SDK */;

[bleConnect getBluetoothInfo:^(TSBluetoothSystem *bluetoothInfo, NSError *error) {
if (error) {
TSLog(@"Failed to get Bluetooth info: %@", error.localizedDescription);
return;
}

if (bluetoothInfo.bleInfo) {