Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
iOS Documentation
SDLFileManager

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 (nonatomic, copy, readonly) NSSet<SDLFileName *> *_Nonnull remoteFileNames;

Swift

var remoteFileNames: Set<String> { get }

bytesAvailable

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

Objective-C

@property (nonatomic, readonly) NSUInteger bytesAvailable;

Swift

var bytesAvailable: UInt { get }

currentState

The state of the file manager.

Objective-C

@property (nonatomic, copy, readonly) 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 (nonatomic, copy, readonly) 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 (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:configuration:

Creates a new file manager with a specified connection manager and configuration

Objective-C

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

Parameters

manager

A connection manager to use to forward on RPCs

configuration

A configuration for this file manager session

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() async throws -> Bool

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()

-hasUploadedFile:

Check if the remote system contains a file

Objective-C

- (BOOL)hasUploadedFile:(nonnull SDLFile *)file;

Swift

func hasUploadedFile(_ file: SDLFile) -> Bool

Parameters

file

The file to check

Return Value

Whether or not the remote system has the file

-deleteRemoteFileWithName:completionHandler:

Delete a file stored on the remote system

Objective-C

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

Swift

func delete(fileName name: String) async throws -> (Bool, UInt)

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.

-deleteRemoteFilesWithNames:completionHandler:

Deletes an array of files on the remote file system. The files are deleted in the order in which they are added to the array, with the first file to be deleted at index 0. The delete queue is sequential, meaning that once a delete request is sent to Core, the queue waits until a response is received from Core before the next delete request is sent.

Objective-C

- (void)deleteRemoteFilesWithNames:(nonnull NSArray<SDLFileName *> *)names
                 completionHandler:
                     (nullable SDLFileManagerMultiDeleteCompletionHandler)
                         completionHandler;

Swift

func delete(fileNames names: [String]) async throws

Parameters

names

The names of the files to be deleted

completionHandler

an optional SDLFileManagerMultiDeleteCompletionHandler

-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 upload(file: SDLFile) async throws -> (Bool, UInt)

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.

-uploadFiles:progressHandler:completionHandler:

Uploads an array of files to the remote file system. The files will be uploaded in the order in which they are added to the array, with the first file to be uploaded at index 0. The upload queue is sequential, meaning that once a upload request is sent to Core, the queue waits until a response is received from Core before the next upload request is sent.

The optional progress handler can be used to keep track of the upload progress. After each file upload, the progress handler returns the upload percentage and an error, if one occurred during the upload process. The progress handler also includes an option to cancel the upload of all remaining files in queue.

Objective-C

- (void)uploadFiles:(nonnull NSArray<SDLFile *> *)files
      progressHandler:
          (nullable SDLFileManagerMultiUploadProgressHandler)progressHandler
    completionHandler:
        (nullable SDLFileManagerMultiUploadCompletionHandler)completionHandler;

Swift

func upload(files: [SDLFile], progressHandler: SDLFileManagerMultiUploadProgressHandler?) async throws

Parameters

files

An array of SDLFiles to be sent

progressHandler

an optional SDLFileManagerMultiUploadProgressHandler

completionHandler

an optional SDLFileManagerMultiUploadCompletionHandler

-uploadFiles:completionHandler:

Uploads an array of files to the remote file system. The files will be uploaded in the order in which they are added to the array, with the first file to be uploaded at index 0. The upload queue is sequential, meaning that once an upload request is sent to Core, the queue waits until a response is received from Core before the next upload request is sent.

Objective-C

- (void)uploadFiles:(nonnull NSArray<SDLFile *> *)files
    completionHandler:
        (nullable SDLFileManagerMultiUploadCompletionHandler)completionHandler;

Swift

func upload(files: [SDLFile]) async throws

Parameters

files

An array of SDLFiles to be sent

completionHandler

An optional SDLFileManagerMultiUploadCompletionHandler

-fileNeedsUpload:

Check if an SDLFile needs to be uploaded to Core or not. This method differs from hasUploadedFile() because it takes the isStaticIcon and overwrite properties into consideration.

For example, if the file is static icon, the method always returns false.

If the file is dynamic, it returns true in one of these situations: 1) the file has the overwrite property set to true, 2) the file hasn’t been uploaded to Core before.

Objective-C

- (BOOL)fileNeedsUpload:(nullable SDLFile *)file;

Swift

func fileNeedsUpload(_ file: SDLFile?) -> Bool

Parameters

file

the SDLFile that needs to be checked

Return Value

BOOL that tells whether file needs to be uploaded to Core or not

-uploadArtwork:completionHandler:

Uploads an artwork file to the remote file system and returns the name of the uploaded artwork once completed. If an artwork with the same name is already on the remote system, the artwork is not uploaded and the artwork name is simply returned.

Objective-C

- (void)uploadArtwork:(nonnull SDLArtwork *)artwork
    completionHandler:
        (nullable SDLFileManagerUploadArtworkCompletionHandler)completion;

Swift

func upload(artwork: SDLArtwork) async throws -> (Bool, String, UInt)

Parameters

artwork

A SDLArwork containing an image to be sent

completion

An optional completion handler that returns the name of the uploaded artwork. It also returns an error if the upload fails.

-uploadArtworks:completionHandler:

Uploads an array of artworks to the remote file system. The artworks will be uploaded in the order in which they are added to the array, with the first file to be uploaded at index 0. The upload queue is sequential, meaning that once an upload request is sent to Core, the queue waits until a response is received from Core before the next upload request is sent.

Objective-C

- (void)uploadArtworks:(nonnull NSArray<SDLArtwork *> *)artworks
     completionHandler:
         (nullable SDLFileManagerMultiUploadArtworkCompletionHandler)completion;

Swift

func upload(artworks: [SDLArtwork]) async throws -> [String]

Parameters

artworks

An array of SDLArtworks to be sent

completion

An optional SDLFileManagerMultiUploadArtworkCompletionHandler

-uploadArtworks:progressHandler:completionHandler:

Uploads an array of artworks to the remote file system. The artworks will be uploaded in the order in which they are added to the array, with the first file to be uploaded at index 0. The upload queue is sequential, meaning that once an upload request is sent to Core, the queue waits until a response is received from Core before the next upload request is sent.

The optional progress handler can be used to keep track of the upload progress. After each artwork upload, the progress handler returns the artwork name, the upload percentage and an error, if one occurred during the upload process. The progress handler also includes an option to cancel the upload of all remaining files in queue.

Objective-C

- (void)uploadArtworks:(nonnull NSArray<SDLArtwork *> *)artworks
       progressHandler:
           (nullable SDLFileManagerMultiUploadArtworkProgressHandler)
               progressHandler
     completionHandler:
         (nullable SDLFileManagerMultiUploadArtworkCompletionHandler)completion;

Swift

func upload(artworks: [SDLArtwork], progressHandler: SDLFileManagerMultiUploadArtworkProgressHandler?) async throws -> [String]

Parameters

artworks

An array of SDLArtworks to be sent

progressHandler

An optional SDLFileManagerMultiUploadArtworkProgressHandler

completion

An optional SDLFileManagerMultiUploadArtworkCompletionHandler

+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.

View on GitHub.com
Previous Section Next Section