This guide explains how to use JoywayLib.iOS static library to implement iBeacon device configuration
Place the JoywayLib directory in the project root:
JoywayBeacon.iOS/
├── JoywayLib/
│ ├── libJoywayLib.a # Static library file
│ ├── DeviceConfig/
│ │ ├── DeviceConfig.h # Device configuration manager interface
│ │ └── iBeaconConfigParam.h # iBeacon parameter encapsulation class
│ ├── BT/ # Bluetooth related headers
│ └── ...other dependencies
└── JoywayBeacon/
└── ...project source code
libJoywayLib.a$(SRCROOT)/JoywayLibManages the complete flow of Bluetooth connection, login, parameter reading and saving
configStateworkingParamsFromDeviceinitWithDeviceMac:devicePassword:paramLen:eventHandler:startstopsaveParamsToDevice:onConnectStatusChanged:status:isConnected:onParamsRead:params:onParamsSaved:success:errorMsg:onFirmwareVersionReceived:fwpId:onLoginFailed:onFirmwareVersionQueryFailed:onDeviceFound:onParamsQueryStarted:onLoginStarted:Encapsulates iBeacon configuration parameters with serialization capabilities
uuidmajorminortxPowerintervaluseBuzzeruseLedbeaconNamerssiAtOneMeteradv1Intervaladv1TimeLenadv2Intervaladv2TimeLenadv1NeverStopadv2NeverStopdevicePasswordgetWorkingParamsDatagetBytes_UUID1/UUID2/MajorMinor/TxPower/...getBytesDataListToSend// 1. Import headers
#import "DeviceConfig.h"
#import "iBeaconConfigParam.h"
// 2. Declare protocol conformance
@interface iBeaconConfigViewController : UIViewController <DeviceConfigEventHandler>
// 3. Initialize DeviceConfig
self.deviceConfig = [[DeviceConfig alloc] initWithDeviceMac:self.mac
devicePassword:self.password
paramLen:72
eventHandler:self];
// 4. Start configuration flow (connect → login → query params)
[self.deviceConfig start];
- (void)onConnectStatusChanged:(NSString*)mac status:(NSString*)status isConnected:(BOOL)isConnected {
if (isConnected) {
NSLog(@"Device connected");
} else {
NSLog(@"Connection status: %@", status);
if ([status isEqualToString:@"连接失败"]) {
// Connection failed, show error to user
}
}
}
- (void)onLoginFailed:(NSString*)mac {
NSLog(@"Login failed, wrong password");
// Show password error to user, close page
}
- (void)onParamsRead:(NSString*)mac params:(NSMutableArray<NSNumber*>*)params {
NSLog(@"Successfully read device parameters, %ld bytes", params.count);
// Parse parameters and display to UI
// params is an array of 72 NSNumber*, each representing a byte (0-255)
// Example: Parse password (first 8 bytes)
NSMutableString *password = [NSMutableString string];
for (int i = 0; i < 8 && i < params.count; i++) {
uint8_t byte = [params[i] unsignedCharValue];
if (byte != 0) [password appendFormat:@"%c", byte];
}
// Parse other parameters...
}
// 1. Create parameter object iBeaconConfigParam *param = [[iBeaconConfigParam alloc] init]; param.uuid = @"00000000-0000-0000-0000-000000000000"; param.major = 1; param.minor = 1; param.txPower = -60; param.interval = 100; param.useBuzzer = YES; param.useLed = YES; param.beaconName = @"MyBeacon"; param.devicePassword = @"000000"; // ...set other parameters // 2. Generate 72-byte working parameters data NSData *paramsData = [param getWorkingParamsData]; // 3. Send save command [self.deviceConfig saveParamsToDevice:paramsData];
- (void)onParamsSaved:(NSString*)mac success:(BOOL)success errorMsg:(NSString*)errorMsg {
if (success) {
NSLog(@"Configuration saved successfully");
// Disconnect and close page
[self.deviceConfig stop];
[self dismissViewControllerAnimated:YES completion:nil];
} else {
NSLog(@"Configuration save failed: %@", errorMsg);
// Show error to user, close page
[self dismissViewControllerAnimated:YES completion:nil];
}
}
User clicks Connect button
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 1. Show login dialog, enter device password │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 2. Check if device is already connected │
│ ├─ Connected → Send login command directly │
│ └─ Not connected → Start Bluetooth scanning (600s timeout)│
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 3. Device found → Stop scanning → Connect device (30s timeout)│
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 4. Connected → Wait 2 seconds (GATT ready) → Send login │
│ command (30s timeout) │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 5. Login success → Query firmware version → Query working │
│ parameters (30s timeout) │
│ ├─ Login failed → Show password error → Close page │
│ └─ Firmware version query failed → Show error → Continue│
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 6. Parameters received → Parse and display → User modifies │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 7. User clicks Save → Validate parameters → Send save │
│ command (30s timeout) │
│ ├─ Save success → Disconnect → Close page │
│ └─ Save failed → Show error → Close page │
└─────────────────────────────────────────────────────────────┘
[deviceConfig stop] when closing the page to release Bluetooth connection resources