格式化媒体存储
使用 formatStorage 删除已连接设备中存储的全部照片、视频和录音。虽然方法名包含“格式化”,但它实际调用现有的删除全部媒体操作,并不会执行单独的文件系统格式化命令。
:::danger 破坏性操作
此操作会删除设备上的全部媒体,SDK 不提供恢复能力。开始前必须获得用户明确确认。
:::
前提条件
- 等待设备完成连接并进入就绪状态。
- 停止录制,并完成或取消正在进行的媒体导入。
- 操作进行期间禁止重复提交。
使用 AI 辅助实现
使用 AI 开发
让 AI 帮助实现此工作流
使用官方“实现 AIBuds 存储格式化”技能,根据你的 App 完成实现。
请阅读并遵循 https://docs-aibuds.github.io/zh-Hans/skills/implement-aibuds-format-storage,使用该技能在当前 iOS 项目中完成“实现 AIBuds 存储格式化”,并验证结果。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");
}
});
}];
}