-
Notifications
You must be signed in to change notification settings - Fork 0
Core Basic Features Factory Reset
The factory reset operation restores the device to its original factory settings, erasing all user data and custom configurations. This operation is useful when preparing a device for resale or troubleshooting persistent issues.
Before performing a factory reset, ensure:
- The device is connected and in a stable state
- All important data has been backed up
- The user understands that all personal data will be erased
AIBuds.xcframework
In the files where you want to use the SDK, import the main header:
import AIBuds#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>The factoryReset method is defined in the following protocol. The protocol inherits from the base device API protocol.
/// Defines common device operations including factory reset
protocol DeviceCommonAPI: DeviceAPI {
/// Factory reset
/// - Parameters:
/// - completion: Completion callback that returns the operation result
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func factoryReset(_ completion: AIBudsCompletionHandler?)
}/// Defines common device operations including factory reset
@protocol AIBudsDeviceCommonAPI <AIBudsDeviceAPI>
/// Factory reset
/// - Parameters:
/// - completion: Completion callback that returns the operation result
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)factoryResetWithCompletion:(AIBudsCompletionHandler)completion;
@endRestores the device to its original factory settings, erasing all user data and custom configurations.
iOS 13.0+
/// Factory reset
/// - Parameters:
/// - completion: Completion callback that returns the operation result
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func factoryReset(_ completion: AIBudsCompletionHandler?)/// Factory reset
/// - Parameters:
/// - completion: Completion callback that returns the operation result
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)factoryResetWithCompletion:(AIBudsCompletionHandler)completion;| Parameter | Type | Description |
|---|---|---|
| completion | AIBudsCompletionHandler? | Optional completion callback that is called when the operation completes. |
Callback Parameters:
| Name | Type | Description |
|---|---|---|
| success | Bool |
true if the operation succeeded, false otherwise. |
| error | NSError? | Contains error information if the operation failed, nil otherwise. |
This method does not return a value directly. The result is provided through the completion callback.
import AIBuds
class DeviceManager {
/// The connected device
weak var device: DeviceConvertible?
/// Performs factory reset on the connected device
func performFactoryReset() {
// Ensure the device supports factory reset protocol
guard let device = device as? DeviceCommonAPI else {
print("Device does not support factory reset")
return
}
// Execute factory reset with completion handler
device.factoryReset { [weak self] success, error in
// Handle failure case
if !success {
let errorMessage = {
if let error = error {
return "\(error)"
}
return "Unknown error"
}()
print("Factory reset failed: \(errorMessage)")
return
}
// Handle success case
print("Factory reset completed successfully")
}
}
}#import <AIBuds/AIBuds.h>
@interface DeviceManager ()
/// The connected device
@property(weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)performFactoryReset {
__weak typeof(self) weakSelf = self;
id<AIBudsDeviceCommonAPI> device = (id<AIBudsDeviceCommonAPI>)self.device;
// Ensure the device supports factory reset protocol
if ([device conformsToProtocol:@protocol(AIBudsDeviceCommonAPI)]) {
// Execute factory reset with completion handler
[device factoryResetWithCompletion:^(BOOL success, NSError *_Nullable error) {
// Handle failure case
if (!success) {
NSLog(@"Factory reset failed: %@", error);
return;
}
// Handle success case
NSLog(@"Factory reset completed successfully");
}];
}
}
@endThe completion handler may return the following error types:
Error Domain: AIBudsSDK.ErrorDomain
| Error Code | Description | Recovery Suggestion |
|---|---|---|
| .deviceNotConnected | Device is not connected | Ensure device is paired and connected |
| .bleCommandExecFailedDueToTimeout | Operation timed out | Retry the operation |
| .deviceBusy | Device is busy with another operation | Wait for ongoing operations to complete |
| .deviceNotSupport | Factory reset is not supported on this device | Check device capabilities before calling |
| Error Code | Description | Recovery Suggestion |
|---|---|---|
| AIBudsSdkErrorCodeDeviceNotConnected | Device is not connected | Ensure device is paired and connected |
| AIBudsSdkErrorCodeBleCommandExecFailedDueToTimeout | Operation timed out | Retry the operation |
| AIBudsSdkErrorCodeDeviceBusy | Device is busy with another operation | Wait for ongoing operations to complete |
| AIBudsSdkErrorCodeDeviceNotSupport | Factory reset is not supported on this device | Check device capabilities before calling |
-
Confirm with User: Always display a confirmation dialog before initiating a factory reset, as this operation is irreversible.
-
Handle Background Execution: Wrap the completion handler in a
DispatchQueue.main.asyncblock when updating UI. -
Weak Self Reference: Use
[weak self]in the completion handler to prevent retain cycles. -
Check Protocol Conformance: Verify the device conforms to
DeviceCommonAPIprotocol before calling the method. -
Clean Up References: After a successful factory reset, you may need to re-pair the device.
- Factory reset may take several seconds to complete
- The device will disconnect and reset during this operation
- All user data including paired devices, settings, and stored media will be erased
- The device will restart automatically after the reset completes
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