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.
A set of all names of files known on the remote head unit. Known files can be used or deleted on the remote system.
@property (nonatomic, copy, readonly) NSSet<SDLFileName *> *_Nonnull remoteFileNames;
var remoteFileNames: Set<String> { get }
The number of bytes still available for files for this app.
@property (nonatomic, readonly) NSUInteger bytesAvailable;
var bytesAvailable: UInt { get }
The state of the file manager.
@property (nonatomic, copy, readonly) NSString *_Nonnull currentState;
var currentState: String { get }
The currently pending transactions (Upload, Delete, and List Files) in the file manager
@property (nonatomic, copy, readonly) NSArray<__kindof NSOperation *> *_Nonnull pendingTransactions;
var pendingTransactions: [Operation] { get }
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.
@property (nonatomic) BOOL suspended;
var suspended: Bool { get set }
Initialize the class…or not, since this method is unavailable. Dependencies must be injected using initWithConnectionManager:
- (nonnull instancetype)init;
nil
Creates a new file manager with a specified connection manager and configuration
- (nonnull instancetype)
initWithConnectionManager:(nonnull id<SDLConnectionManagerType>)manager
configuration:
(nonnull SDLFileManagerConfiguration *)configuration;
A connection manager to use to forward on RPCs
A configuration for this file manager session
An instance of SDLFileManager
The manager stars up and attempts to fetch its initial list and transfer initial files.
- (void)startWithCompletionHandler:
(nullable SDLFileManagerStartupCompletionHandler)completionHandler;
func start() async throws -> Bool
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.
Cancels all file manager operations and deletes all associated data.
- (void)stop;
func stop()
Check if the remote system contains a file
- (BOOL)hasUploadedFile:(nonnull SDLFile *)file;
func hasUploadedFile(_ file: SDLFile) -> Bool
The file to check
Whether or not the remote system has the file
Delete a file stored on the remote system
- (void)deleteRemoteFileWithName:(nonnull SDLFileName *)name
completionHandler:
(nullable SDLFileManagerDeleteCompletionHandler)completion;
func delete(fileName name: String) async throws -> (Bool, UInt)
The name of the remote file. It should be a name currently stored in remoteFileNames
An optional completion handler that sends an error should one occur.
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.
- (void)deleteRemoteFilesWithNames:(nonnull NSArray<SDLFileName *> *)names
completionHandler:
(nullable SDLFileManagerMultiDeleteCompletionHandler)
completionHandler;
func delete(fileNames names: [String]) async throws
The names of the files to be deleted
an optional SDLFileManagerMultiDeleteCompletionHandler
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.
- (void)uploadFile:(nonnull SDLFile *)file
completionHandler:
(nullable SDLFileManagerUploadCompletionHandler)completion;
func upload(file: SDLFile) async throws -> (Bool, UInt)
An SDLFile that contains metadata about the file to be sent
An optional completion handler that sends an error should one occur.
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.
- (void)uploadFiles:(nonnull NSArray<SDLFile *> *)files
progressHandler:
(nullable SDLFileManagerMultiUploadProgressHandler)progressHandler
completionHandler:
(nullable SDLFileManagerMultiUploadCompletionHandler)completionHandler;
func upload(files: [SDLFile], progressHandler: SDLFileManagerMultiUploadProgressHandler?) async throws
An array of SDLFiles to be sent
an optional SDLFileManagerMultiUploadProgressHandler
an optional SDLFileManagerMultiUploadCompletionHandler
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.
- (void)uploadFiles:(nonnull NSArray<SDLFile *> *)files
completionHandler:
(nullable SDLFileManagerMultiUploadCompletionHandler)completionHandler;
func upload(files: [SDLFile]) async throws
An array of SDLFiles to be sent
An optional SDLFileManagerMultiUploadCompletionHandler
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.
- (BOOL)fileNeedsUpload:(nullable SDLFile *)file;
func fileNeedsUpload(_ file: SDLFile?) -> Bool
the SDLFile that needs to be checked
BOOL that tells whether file needs to be uploaded to Core or not
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.
- (void)uploadArtwork:(nonnull SDLArtwork *)artwork
completionHandler:
(nullable SDLFileManagerUploadArtworkCompletionHandler)completion;
func upload(artwork: SDLArtwork) async throws -> (Bool, String, UInt)
A SDLArwork containing an image to be sent
An optional completion handler that returns the name of the uploaded artwork. It also returns an error if the upload fails.
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.
- (void)uploadArtworks:(nonnull NSArray<SDLArtwork *> *)artworks
completionHandler:
(nullable SDLFileManagerMultiUploadArtworkCompletionHandler)completion;
func upload(artworks: [SDLArtwork]) async throws -> [String]
An array of SDLArtworks to be sent
An optional SDLFileManagerMultiUploadArtworkCompletionHandler
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.
- (void)uploadArtworks:(nonnull NSArray<SDLArtwork *> *)artworks
progressHandler:
(nullable SDLFileManagerMultiUploadArtworkProgressHandler)
progressHandler
completionHandler:
(nullable SDLFileManagerMultiUploadArtworkCompletionHandler)completion;
func upload(artworks: [SDLArtwork], progressHandler: SDLFileManagerMultiUploadArtworkProgressHandler?) async throws -> [String]
An array of SDLArtworks to be sent
An optional SDLFileManagerMultiUploadArtworkProgressHandler
An optional SDLFileManagerMultiUploadArtworkCompletionHandler
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.
+ (nonnull NSURL *)temporaryFileDirectory;
class func temporaryFileDirectory() -> URL
An NSURL pointing to the location on disk where SDL’s temporary files are stored.