If you use the SDLScreenManager
, image uploading for template graphics, soft buttons, and menu items is handled for you behind the scenes. However, you will still need to manually upload your images if you need images in an alert, VR help lists, turn-by-turn directions, or other features not currently covered by the SDLScreenManager
.
You should be aware of these four things when using images in your SDL app:
hmiLevel
is NONE
. For more information about permissions, please review Understanding Permissions.Before uploading images to a head unit you should first check if the head unit supports graphics. If not, you should avoid uploading unnecessary image data. To check if graphics are supported, check the SDLManager.systemCapabilityManager.defaultMainWindowCapability
property once the SDLManager
has started successfully.
__weak typeof (self) weakSelf = self; [self.sdlManager startWithReadyHandler:^(BOOL success, NSError * _Nullable error) { if (!success) { <#Manager errored while starting up#> return; } SDLWindowCapability *mainWindowCapability = weakSelf.sdlManager.systemCapabilityManager.defaultMainWindowCapability; BOOL graphicsSupported = (mainWindowCapability.imageFields.count > 0); }];
sdlManager.start { [weak self] (success, error) in guard let self = self else { return } guard success else { <#Manager errored while starting up#> return } let mainWindowCapability = self.sdlManager.systemCapabilityManager.defaultMainWindowCapability let graphicsSupported = ((mainWindowCapability?.imageFields?.count ?? 0) > 0) }
The SDLFileManager
uploads files and keeps track of all the uploaded files names during a session. To send data with the SDLFileManager
, you need to create either a SDLFile
or SDLArtwork
object. SDLFile
objects are created with a local NSURL
or NSData
; SDLArtwork
a UIImage
.
UIImage* image = [UIImage imageNamed:@"<#Image Name#>"]; if (!image) { <#Error reading from assets#> return; } SDLArtwork *artwork = [SDLArtwork persistentArtworkWithImage:image asImageFormat:<#SDLArtworkImageFormat#>]; [self.sdlManager.fileManager uploadArtwork:artwork completionHandler:^(BOOL success, NSString * _Nonnull artworkName, NSUInteger bytesAvailable, NSError * _Nullable error) { if (error != nil) { return; } <#Image Upload Successful#> // To send the image as part of a show request, create a SDLImage object using the artworkName SDLImage *image = [[SDLImage alloc] initWithName:artworkName isTemplate:<#BOOL#>]; }];
guard let image = UIImage(named: "<#Image Name#>") else { <#Error reading from assets#> return } let artwork = SDLArtwork(image: image, persistent: <#Bool#>, as: <#SDLArtworkImageFormat#>) sdlManager.fileManager.upload(artwork: artwork) { (success, artworkName, bytesAvailable, error) in guard error == nil else { return } <#Image Upload Successful#> // To send the image as part of a show request, create a SDLImage object using the artworkName let graphic = SDLImage(name: artworkName, isTemplate: <#Bool#>) }
Similar to other files, artworks can be persistent, batched, overwrite, etc. See Uploading Files for more information.
View on GitHub.com