본문으로 건너뛰기

공장 초기화

공장 초기화 작업은 기기를 원래의 공장 설정으로 복원하고 모든 사용자 데이터와 사용자 정의 구성을 삭제합니다. 이 작업은 기기를 재판매하거나 지속적인 문제를 해결할 때 유용합니다.

전제 조건

공장 초기화를 수행하기 전에 다음을 확인하세요:

  • 기기가 연결되어 있고 안정적인 상태에 있는지
  • 모든 중요한 데이터가 백업되었는지
  • 사용자가 모든 개인 데이터가 삭제된다는 것을 이해하는지

AI를 활용해 구현

AI로 구현

AI로 이 워크플로 구현

공식 “AIBuds 공장 초기화 구현” 스킬을 사용해 앱에 맞게 구현하세요.

https://docs-aibuds.github.io/ko/skills/implement-aibuds-factory-reset을 읽고 지침을 따르세요. 이 스킬로 “AIBuds 공장 초기화 구현”을 이 iOS 프로젝트에 구현하고 검증하세요.
공식 스킬 보기

API 참조

프레임워크

AIBuds.xcframework

가져오기

SDK를 사용하려는 파일에서 메인 헤더를 가져옵니다:

Swift
import AIBuds

프로토콜

factoryReset 메서드는 다음 프로토콜에 정의되어 있습니다. 이 프로토콜은 기본 기기 API 프로토콜을 상속합니다.

Swift
/// 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?)
}

인스턴스 메서드

기기를 원래의 공장 설정으로 복원하고 모든 사용자 데이터와 사용자 정의 구성을 삭제합니다.

iOS 13.0+

Swift
/// 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?)

매개변수

매개변수타입설명
completionAIBudsCompletionHandler?작업이 완료되면 호출되는 선택적 완료 콜백입니다.

콜백 매개변수:

이름타입설명
successBool작업이 성공한 경우 true, 그 외는 false
errorNSError?작업이 실패한 경우 오류 정보를 포함하고, 성공한 경우 nil

반환 값

이 메서드는 직접 값을 반환하지 않습니다. 결과는 완료 콜백을 통해 제공됩니다.

사용 예시

Swift
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")
        }
    }
}

오류 처리

완료 핸들러는 다음 오류 유형을 반환할 수 있습니다:

오류 도메인: AIBudsSDK.ErrorDomain

오류 코드설명해결 방법
.deviceNotConnected기기가 연결되어 있지 않습니다기기가 페어링되고 연결되어 있는지 확인하세요
.bleCommandExecFailedDueToTimeout작업이 시간 초과되었습니다작업을 다시 시도하세요
.deviceBusy기기가 다른 작업으로 바쁩니다진행 중인 작업이 완료될 때까지 기다리세요
.deviceNotSupport이 기기에서는 공장 초기화가 지원되지 않습니다호출하기 전에 기기 기능을 확인하세요

권장 사항

  1. 사용자에게 확인: 이 작업은 취소할 수 없으므로 공장 초기화를 시작하기 전에 항상 확인 대화 상자를 표시하세요.

  2. 백그라운드 실행 처리: UI를 업데이트할 때 완료 핸들러를 DispatchQueue.main.async 블록으로 감싸세요.

  3. 약한 참조 사용: 유지 순환을 방지하려면 완료 핸들러에서 [weak self]를 사용하세요.

  4. 프로토콜 적합성 확인: 메서드를 호출하기 전에 기기가 DeviceCommonAPI 프로토콜에 적합한지 확인하세요.

  5. 참조 정리: 공장 초기화가 성공한 후 기기를 다시 페어링해야 할 수 있습니다.

참고 사항

  • 공장 초기화는 완료되기까지 몇 초가 걸릴 수 있습니다
  • 이 작업 중에 기기는 연결이 끊어지고 재설정됩니다
  • 페어링된 기기, 설정, 저장된 미디어를 포함한 모든 사용자 데이터가 삭제됩니다
  • 리셋이 완료된 후 기기는 자동으로 다시 시작합니다