-
Notifications
You must be signed in to change notification settings - Fork 0
Core Device Info Sync Time
Synchronize the connected device's internal clock with the current time. Use this operation when the device needs to align its clock without supplying a specific date.
Before synchronizing the device time, ensure:
- The device is connected and in a stable state
- The device supports the
DeviceInfoAPIprotocol
AIBuds.xcframework
In the files where you want to use the SDK, import the main framework:
import AIBuds#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>The syncDeviceTime method is defined in DeviceInfoAPI. The protocol inherits from the base device API protocol.
/// The protocol for device information related API.
protocol DeviceInfoAPI: DeviceAPI {
/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func syncDeviceTime(_ completion: AIBudsStatusCodeCompletionHandler?)
}/// The protocol for device information related API.
@protocol AIBudsDeviceInfoAPI <AIBudsDeviceAPI>
/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
- (void)syncDeviceTimeWithCompletion:(AIBudsStatusCodeCompletionHandler _Nullable)completion;
@endSynchronizes the device time with the current time.
/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func syncDeviceTime(_ completion: AIBudsStatusCodeCompletionHandler?)/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
- (void)syncDeviceTimeWithCompletion:(AIBudsStatusCodeCompletionHandler _Nullable)completion;| Parameter | Type | Description |
|---|---|---|
completion |
AIBudsStatusCodeCompletionHandler? |
Optional completion handler called when the operation finishes. |
Callback Parameters:
| Name | Type | Description |
|---|---|---|
success |
Bool / BOOL
|
true if the operation succeeded; otherwise false. |
statusCode |
NSNumber? |
The status code returned by the device. The SDK documents this value as nil when the operation fails. |
error |
NSError? |
Error details if the operation failed; otherwise nil. |
This method does not return a value directly. The result is provided through the completion handler.
import AIBuds
final class DeviceManager {
/// The connected device
weak var device: DeviceConvertible?
/// Synchronizes the connected device with the current time
func synchronizeDeviceTime() {
guard let device = device as? DeviceInfoAPI else {
print("Device does not support time synchronization")
return
}
device.syncDeviceTime { success, statusCode, error in
if !success {
print(
"Time synchronization failed: " +
(error?.localizedDescription ?? "Unknown error")
)
return
}
print(
"Time synchronized successfully. Status code: " +
(statusCode?.stringValue ?? "N/A")
)
}
}
}#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>
@interface DeviceManager ()
/// The connected device
@property (weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)synchronizeDeviceTime {
id<AIBudsDeviceInfoAPI> device = (id<AIBudsDeviceInfoAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceInfoAPI)]) {
NSLog(@"Device does not support time synchronization");
return;
}
[device syncDeviceTimeWithCompletion:^(
BOOL success,
NSNumber * _Nullable statusCode,
NSError * _Nullable error
) {
if (!success) {
NSLog(@"Time synchronization failed: %@",
error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"Time synchronized successfully. Status code: %@",
statusCode ?: @"N/A");
}];
}
@endThe completion handler reports the result of the synchronization:
- Check
successbefore treating the operation as complete. - When
successisfalse, useerrorfor failure details. - Preserve
statusCodefor diagnostics or device-specific handling when it is available. - Do not assume a particular error or status code unless it is documented for the target device.
-
Check Protocol Conformance: Confirm that the device supports
DeviceInfoAPIbefore calling the method. -
Call After Connection: Synchronize only after the device is connected and ready.
-
Handle All Completion Values: Evaluate
success,statusCode, anderrorinstead of relying onerroralone. -
Update UI on the Main Queue: Dispatch completion-driven UIKit updates to the main queue.
-
syncDeviceTimedoes not accept a targetDate; usesetDeviceTime(to:completion:)when you need to provide one. - The public API describes synchronization with the current time but does not define a UTC conversion contract.
- Support for time synchronization can vary by device model and firmware.
AIBuds SDK documentation · Full documentation · API Reference
- Introduction
- Getting Started
- Core Concepts
-
Core Features
- Basic Features
- Device Info
- Find Device
- Physical Operations
- Work Mode
- Work Status
- Wear Detection
- Volume Control
- Music Control
- TWS
- Equalizer
- ANC
- Audio
- Camera
- Remote Camera
- File Import
- Teleprompter
- Segment Navigation
- Live Streaming
- Device Applications
- OTA
- Camera OTA
- Service Auth
- AI Services
- Voice Assistant
- Logging
- Advanced Topics
- Releases
- Troubleshooting