Skip to content

Core Basic Features Format Storage

Mr.P edited this page Aug 29, 2026 · 1 revision

Format Media Storage

Use formatStorage to delete every photo, video, and audio recording stored on a connected device. Despite its name, this API delegates to the existing delete-all-media operation; it does not issue a separate filesystem-format command.

Destructive operation

This action removes all device media and is not presented as recoverable by the SDK. Require explicit user confirmation before starting it.

Prerequisites

  • Wait until the device is connected and ready.
  • Stop recording and finish or cancel active media imports.
  • Disable repeated submission while the operation is in progress.

API Behavior

The completion callback reports whether the underlying delete-all request was accepted. It does not return refreshed media counts or storage information.

Usage Example

Swift

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

Objective-C

#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");
                }
            });
        }];
}

Result Handling

  • On success, refresh the UI with Query Media Count and Query Storage Information.
  • On failure, preserve the returned error for diagnostics and allow retry only after the current request finishes.
  • If the device disconnects before completion, treat the result as indeterminate until device state is queried again.

AIBuds SDK iOS Wiki

Clone this wiki locally