出荷時設定にリセット
出荷時設定リセット操作により、デバイスは元の出荷時設定に復元され、すべてのユーザーデータとカスタム設定が消去されます。この操作は、デバイスを再販売する準備をするときや、持続的な問題をトラブルシューティングするときに便利です。
前提条件
出荷時設定リセットを実行する前に、以下を確認してください:
- デバイスが接続されており、安定した状態にある
- すべての重要なデータがバックアップされている
- ユーザーがすべての個人データが消去されることを理解している
AI を活用して実装
AI で実装
AI でこのワークフローを実装
公式の「AIBuds の初期化を実装」スキルを使い、アプリに合わせて実装します。
https://docs-aibuds.github.io/ja/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プロトコルに準拠していることを確認してください。 - 参照のクリーンアップ: 出荷時設定リセットに成功した後、デバイスを再度ペアリングする必要がある場合があります。
注意事項
- 出荷時設定リセットは完了までに数秒かかる場合があります
- この操作中、デバイスは切断されてリセットされます
- ペアリングされたデバイス、設定、保存されたメディアを含むすべてのユーザーデータが消去されます
- リセット完了後、デバイスは自動的に再起動します