メディアストレージのフォーマット
formatStorage を使用して、接続済みデバイスに保存された写真、動画、録音をすべて削除します。この API は既存の全メディア削除処理を呼び出すもので、別のファイルシステムフォーマット命令は実行しません。
:::danger 破壊的な操作
デバイス上のすべてのメディアが削除され、SDK から復元することはできません。開始前にユーザーの明示的な確認を求めてください。
:::
前提条件
- デバイスが接続済みで準備完了になるまで待ちます。
- 録画を停止し、進行中のメディア取り込みを完了またはキャンセルします。
- 処理中は重複実行を無効にします。
AI を活用して実装
AI で実装
AI でこのワークフローを実装
公式の「AIBuds ストレージのフォーマット」スキルを使い、アプリに合わせて実装します。
https://docs-aibuds.github.io/ja/skills/implement-aibuds-format-storage を読み、その指示に従ってください。このスキルで「AIBuds ストレージのフォーマット」をこの iOS プロジェクトに実装し、検証してください。API の動作
完了コールバックは全削除リクエストが受け付けられたかを通知します。更新後のメディア件数やストレージ情報は返しません。
使用例
- Swift
- Objective-C
import AIBuds
func formatMediaStorage(on device: DeviceConvertible) {
guard let device = device as? DeviceCommonAPI else {
print("This device does not support common operations")
return
}
device.formatStorage { success, error in
DispatchQueue.main.async {
if success {
print("All device media was deleted")
} else {
print("Delete failed: \(error?.localizedDescription ?? "Unknown error")")
}
}
}
}#import <AIBuds/AIBuds-Swift.h>
- (void)formatMediaStorageOnDevice:(id<AIBudsDeviceConvertible>)device {
if (![device conformsToProtocol:@protocol(AIBudsDeviceCommonAPI)]) {
NSLog(@"This device does not support common operations");
return;
}
[(id<AIBudsDeviceCommonAPI>)device
formatStorageWithCompletion:^(BOOL success, NSError *_Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
NSLog(@"All device media was deleted");
} else {
NSLog(@"Delete failed: %@",
error.localizedDescription ?: @"Unknown error");
}
});
}];
}結果の処理
- 成功後、メディア件数の照会とストレージ情報の照会で画面を更新します。
- 失敗時は診断用にエラーを保持し、現在の要求が終了してから再試行を許可します。
- 完了前に切断された場合は、デバイス状態を再照会するまで結果を未確定として扱います。