SDLFileManager Class Reference

Section Contents

Overview

The SDLFileManager is an RPC manager for the remote file system. After it starts, it will attempt to communicate with the remote file system to get the names of all files. Deleting and Uploading will them queue these changes as transactions. If a delete succeeds, the local list of remote files will remove that file name, and likewise, if an upload succeeds, the local list of remote files will now include that file name.

remoteFileNames

A set of all names of files known on the remote head unit. Known files can be used or deleted on the remote system.

Objective-C

@property (readonly, copy, nonatomic)
    NSSet<SDLFileName *> *_Nonnull remoteFileNames;

Swift

var remoteFileNames: Set

bytesAvailable

The number of bytes still available for files for this app.

Objective-C

@property (readonly, assign, nonatomic) NSUInteger bytesAvailable;

Swift

var bytesAvailable: UInt { get }

currentState

The state of the file manager.

Objective-C

@property (readonly, copy, nonatomic) NSString *_Nonnull currentState;

Swift

var currentState: String { get }

pendingTransactions

The currently pending transactions (Upload, Delete, and List Files) in the file manager

Objective-C

@property (readonly, copy, nonatomic)
    NSArray<__kindof NSOperation *> *_Nonnull pendingTransactions;

Swift

var pendingTransactions: [Operation] { get }

suspended

Whether or not the file manager is suspended. If suspended, the file manager can continue to queue uploads and deletes, but will not actually perform any of those until it is no longer suspended. This can be used for throttling down the file manager if other, important operations are taking place over the accessory connection.

Objective-C

@property (assign, readwrite, nonatomic) BOOL suspended;

Swift

var suspended: Bool { get set }

-init

Initialize the class…or not, since this method is unavailable. Dependencies must be injected using initWithConnectionManager:

Objective-C

- (nonnull instancetype)init;

Return Value

nil

-initWithConnectionManager:

Creates a new file manager with a specified connection manager

Objective-C

- (nonnull instancetype)initWithConnectionManager:
    (nonnull id<SDLConnectionManagerType>)manager;

Parameters

manager

A connection manager to use to forward on RPCs

Return Value

An instance of SDLFileManager

-startWithCompletionHandler:

The manager stars up and attempts to fetch its initial list and transfer initial files.

Objective-C

- (void)startWithCompletionHandler:
    (nullable SDLFileManagerStartupCompletionHandler)completionHandler;

Swift

func start(completionHandler: SDLFileManagerStartupCompletionHandler? = nil)

Parameters

completionHandler

The handler called when the manager is set up or failed to set up with an error. Use weak self when accessing self from the completion handler.

-stop

Cancels all file manager operations and deletes all associated data.

Objective-C

- (void)stop;

Swift

func stop()

-deleteRemoteFileWithName:completionHandler:

Delete a file stored on the remote system

Objective-C

- (void)deleteRemoteFileWithName:(nonnull SDLFileName *)name
               completionHandler:
                   (nullable SDLFileManagerDeleteCompletionHandler)completion;

Swift

func deleteRemoteFile(withName name: String, completionHandler completion: SDLFileManagerDeleteCompletionHandler? = nil)

Parameters

name

The name of the remote file. It should be a name currently stored in remoteFileNames

completion

An optional completion handler that sends an error should one occur.

-uploadFile:completionHandler:

Upload a file to the remote file system. If a file with the [SDLFile name] already exists, this will overwrite that file. If you do not want that to happen, check remoteFileNames before uploading, or change allowOverwrite to NO.

Objective-C

- (void)uploadFile:(nonnull SDLFile *)file
    completionHandler:
        (nullable SDLFileManagerUploadCompletionHandler)completion;

Swift

func uploadFile(_ file: SDLFile, completionHandler completion: SDLFileManagerUploadCompletionHandler? = nil)

Parameters

file

An SDLFile that contains metadata about the file to be sent

completion

An optional completion handler that sends an error should one occur.

+temporaryFileDirectory

A URL to the directory where temporary files are stored. When an SDLFile is created with NSData, it writes to a temporary file until the file manager finishes uploading it.

The SDL library manages the creation and deletion of these files and you should not have to touch this directory at all.

Objective-C

+ (nonnull NSURL *)temporaryFileDirectory;

Swift

class func temporaryFileDirectory() -> URL

Return Value

An NSURL pointing to the location on disk where SDL’s temporary files are stored.