공장 초기화
공장 초기화 작업은 기기를 원래의 공장 설정으로 복원하고 모든 사용자 데이터와 사용자 정의 구성을 삭제합니다. 이 작업은 기기를 재판매하거나 지속적인 문제를 해결할 때 유용합니다.
전제 조건
공장 초기화를 수행하기 전에 다음을 확인하세요:
- 기기가 연결되어 있고 안정적인 상태에 있는지
- 모든 중요한 데이터가 백업되었는지
- 사용자가 모든 개인 데이터가 삭제된다는 것을 이해하는지
AI를 활용해 구현
AI로 구현
AI로 이 워크플로 구현
공식 “AIBuds 공장 초기화 구현” 스킬을 사용해 앱에 맞게 구현하세요.
https://docs-aibuds.github.io/ko/skills/implement-aibuds-factory-reset을 읽고 지침을 따르세요. 이 스킬로 “AIBuds 공장 초기화 구현”을 이 iOS 프로젝트에 구현하고 검증하세요.API 참조
프레임워크
AIBuds.xcframework
가져오기
SDK를 사용하려는 파일에서 메인 헤더를 가져옵니다:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>프로토콜
factoryReset 메서드는 다음 프로토콜에 정의되어 있습니다. 이 프로토콜은 기본 기기 API 프로토콜을 상속합니다.
- Swift
- Objective-C
/// 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;
@end인스턴스 메서드
기기를 원래의 공장 설정으로 복원하고 모든 사용자 데이터와 사용자 정의 구성을 삭제합니다.
iOS 13.0+
- Swift
- Objective-C
/// 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;매개변수
| 매개변수 | 타입 | 설명 |
|---|---|---|
| completion | AIBudsCompletionHandler? | 작업이 완료되면 호출되는 선택적 완료 콜백입니다. |
콜백 매개변수:
| 이름 | 타입 | 설명 |
|---|---|---|
| success | Bool | 작업이 성공한 경우 true, 그 외는 false |
| error | NSError? | 작업이 실패한 경우 오류 정보를 포함하고, 성공한 경우 nil |
반환 값
이 메서드는 직접 값을 반환하지 않습니다. 결과는 완료 콜백을 통해 제공됩니다.
사용 예시
- Swift
- Objective-C
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");
}];
}
}
@end오류 처리
완료 핸들러는 다음 오류 유형을 반환할 수 있습니다:
오류 도메인: AIBudsSDK.ErrorDomain
- Swift
- Objective-C
| 오류 코드 | 설명 | 해결 방법 |
|---|---|---|
| .deviceNotConnected | 기기가 연결되어 있지 않습니다 | 기기가 페어링되고 연결되어 있는지 확인하세요 |
| .bleCommandExecFailedDueToTimeout | 작업이 시간 초과되었습니다 | 작업을 다시 시도하세요 |
| .deviceBusy | 기기가 다른 작업으로 바쁩니다 | 진행 중인 작업이 완료될 때까지 기다리세요 |
| .deviceNotSupport | 이 기기에서는 공장 초기화가 지원되지 않습니다 | 호출하기 전에 기기 기능을 확인하세요 |
| 오류 코드 | 설명 | 해결 방법 |
|---|---|---|
| AIBudsSdkErrorCodeDeviceNotConnected | 기기가 연결되어 있지 않습니다 | 기기가 페어링되고 연결되어 있는지 확인하세요 |
| AIBudsSdkErrorCodeBleCommandExecFailedDueToTimeout | 작업이 시간 초과되었습니다 | 작업을 다시 시도하세요 |
| AIBudsSdkErrorCodeDeviceBusy | 기기가 다른 작업으로 바쁩니다 | 진행 중인 작업이 완료될 때까지 기다리세요 |
| AIBudsSdkErrorCodeDeviceNotSupport | 이 기기에서는 공장 초기화가 지원되지 않습니다 | 호출하기 전에 기기 기능을 확인하세요 |
권장 사항
-
사용자에게 확인: 이 작업은 취소할 수 없으므로 공장 초기화를 시작하기 전에 항상 확인 대화 상자를 표시하세요.
-
백그라운드 실행 처리: UI를 업데이트할 때 완료 핸들러를
DispatchQueue.main.async블록으로 감싸세요. -
약한 참조 사용: 유지 순환을 방지하려면 완료 핸들러에서
[weak self]를 사용하세요. -
프로토콜 적합성 확인: 메서드를 호출하기 전에 기기가
DeviceCommonAPI프로토콜에 적합한지 확인하세요. -
참조 정리: 공장 초기화가 성공한 후 기기를 다시 페어링해야 할 수 있습니다.
참고 사항
- 공장 초기화는 완료되기까지 몇 초가 걸릴 수 있습니다
- 이 작업 중에 기기는 연결이 끊어지고 재설정됩니다
- 페어링된 기기, 설정, 저장된 미디어를 포함한 모든 사용자 데이터가 삭제됩니다
- 리셋이 완료된 후 기기는 자동으로 다시 시작합니다