summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SmartDeviceLink/SDLArtwork.h36
-rw-r--r--SmartDeviceLink/SDLArtwork.m22
-rw-r--r--SmartDeviceLink_Example/Classes/ProxyManager.m4
3 files changed, 51 insertions, 11 deletions
diff --git a/SmartDeviceLink/SDLArtwork.h b/SmartDeviceLink/SDLArtwork.h
index 79aa8853d..5d31779a3 100644
--- a/SmartDeviceLink/SDLArtwork.h
+++ b/SmartDeviceLink/SDLArtwork.h
@@ -34,7 +34,23 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An instance of this class to be passed to the file manager.
*/
-+ (instancetype)artworkWithImage:(UIImage *)image name:(NSString *)name asImageFormat:(SDLArtworkImageFormat)imageFormat NS_SWIFT_UNAVAILABLE("Use the standard initializer and set persistant to false") __deprecated_msg("Use initWithImage:image persistent:asImageFormat: instead");
++ (instancetype)artworkWithImage:(UIImage *)image name:(NSString *)name asImageFormat:(SDLArtworkImageFormat)imageFormat NS_SWIFT_UNAVAILABLE("Use the standard initializer and set persistant to false") __deprecated_msg("Use artworkWithImage:image asImageFormat: instead");
+
+/**
+ * Convenience Helper to create an ephemeral artwork from an image. A unique name will be assigned to the image. This name is a string representation of the image's data which is created by hashing the data using the MD5 algorithm.
+ *
+ * This is an ephemeral file, it will not be persisted through sessions / ignition cycles. Any files that you do not *know* you will use in future sessions should be created through this method. For example, album / artist artwork should be ephemeral.
+ *
+ * Persistent files should be created using `persistentArtworkWithImage:name:asImageFormat:`
+ *
+ * @warning It is strongly recommended to pass the file url using an SDLFile initializer instead of the image. If you pass the UIImage, it is loaded into memory, and will be dumped to a temporary file. This will create a duplicate file. *Only pass a UIImage if the image is not stored on disk*.
+ *
+ * @param image The UIImage to be sent to the remote head unit
+ * @param imageFormat Whether the image should be converted to a PNG or JPG before transmission. Images with transparency or few colors should be PNGs. Images with many colors should be JPGs.
+ *
+ * @return An instance of this class to be passed to the file manager.
+ */
++ (instancetype)artworkWithImage:(UIImage *)image asImageFormat:(SDLArtworkImageFormat)imageFormat NS_SWIFT_UNAVAILABLE("Use the standard initializer and set persistant to false");
/**
* Convenience Helper to create a persistent artwork from an image.
@@ -51,7 +67,23 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An instance of this class to be passed to the file manager.
*/
-+ (instancetype)persistentArtworkWithImage:(UIImage *)image name:(NSString *)name asImageFormat:(SDLArtworkImageFormat)imageFormat NS_SWIFT_UNAVAILABLE("Use the standard initializer and set persistant to true") __deprecated_msg("Use initWithImage:image persistent:asImageFormat: instead");
++ (instancetype)persistentArtworkWithImage:(UIImage *)image name:(NSString *)name asImageFormat:(SDLArtworkImageFormat)imageFormat NS_SWIFT_UNAVAILABLE("Use the standard initializer and set persistant to true") __deprecated_msg("Use persistentArtworkWithImage:image:asImageFormat instead");
+
+/**
+ * Convenience Helper to create a persistent artwork from an image. A unique name will be assigned to the image. This name is a string representation of the image's data which is created by hashing the data using the MD5 algorithm.
+ *
+ * This is a persistent file, it will be persisted through sessions / ignition cycles. You will only have a limited space for all files, so be sure to only persist files that are required for all or most sessions. For example, menu artwork should be persistent.
+ *
+ * Ephemeral files should be created using `ephemeralArtworkWithImage:name:asImageFormat:`
+ *
+ * @warning It is strongly recommended to pass the file url using an SDLFile initializer instead of the image. If you pass the UIImage, it is loaded into memory, and will be dumped to a temporary file. This will create a duplicate file. *Only pass a UIImage if the image is not stored on disk*.
+ *
+ * @param image The UIImage to be sent to the remote head unit
+ * @param imageFormat Whether the image should be converted to a PNG or JPG before transmission. Images with transparency or few colors should be PNGs. Images with many colors should be JPGs.
+ *
+ * @return An instance of this class to be passed to the file manager.
+ */
++ (instancetype)persistentArtworkWithImage:(UIImage *)image asImageFormat:(SDLArtworkImageFormat)imageFormat NS_SWIFT_UNAVAILABLE("Use the standard initializer and set persistant to true");
/**
* Create a file for transmission to the remote system from a UIImage.
diff --git a/SmartDeviceLink/SDLArtwork.m b/SmartDeviceLink/SDLArtwork.m
index f62c28faa..062374858 100644
--- a/SmartDeviceLink/SDLArtwork.m
+++ b/SmartDeviceLink/SDLArtwork.m
@@ -27,21 +27,29 @@ NS_ASSUME_NONNULL_BEGIN
return [[self alloc] initWithImage:image name:name persistent:NO asImageFormat:imageFormat];
}
++ (instancetype)artworkWithImage:(UIImage *)image asImageFormat:(SDLArtworkImageFormat)imageFormat {
+ return [[self alloc] initWithImage:image persistent:NO asImageFormat:imageFormat];
+}
+
+ (instancetype)persistentArtworkWithImage:(UIImage *)image name:(NSString *)name asImageFormat:(SDLArtworkImageFormat)imageFormat {
return [[self alloc] initWithImage:image name:name persistent:YES asImageFormat:imageFormat];
}
++ (instancetype)persistentArtworkWithImage:(UIImage *)image asImageFormat:(SDLArtworkImageFormat)imageFormat {
+ return [[self alloc] initWithImage:image persistent:YES asImageFormat:imageFormat];
+}
+
#pragma mark Private Lifecycle
- (instancetype)initWithImage:(UIImage *)image name:(NSString *)name persistent:(BOOL)persistent asImageFormat:(SDLArtworkImageFormat)imageFormat {
- return [super initWithData:[self sdl_dataForUIImage:image imageFormat:imageFormat] name:name fileExtension:[self sdl_fileExtensionForImageFormat:imageFormat] persistent:persistent];
+ return [super initWithData:[self.class sdl_dataForUIImage:image imageFormat:imageFormat] name:name fileExtension:[self.class sdl_fileExtensionForImageFormat:imageFormat] persistent:persistent];
}
- (instancetype)initWithImage:(UIImage *)image persistent:(BOOL)persistent asImageFormat:(SDLArtworkImageFormat)imageFormat {
- NSData *imageData = [self sdl_dataForUIImage:image imageFormat:imageFormat];
- NSString *imageName = [self sdl_md5HashFromNSData:imageData];
- return [super initWithData:[self sdl_dataForUIImage:image imageFormat:imageFormat] name:(imageName != nil ? imageName : @"") fileExtension:[self sdl_fileExtensionForImageFormat:imageFormat] persistent:persistent];
+ NSData *imageData = [self.class sdl_dataForUIImage:image imageFormat:imageFormat];
+ NSString *imageName = [self.class sdl_md5HashFromNSData:imageData];
+ return [super initWithData:[self.class sdl_dataForUIImage:image imageFormat:imageFormat] name:(imageName != nil ? imageName : @"") fileExtension:[self.class sdl_fileExtensionForImageFormat:imageFormat] persistent:persistent];
}
/**
@@ -51,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param imageFormat The image format to use when converting the UIImage to NSData
* @return The image data
*/
-- (NSData *)sdl_dataForUIImage:(UIImage *)image imageFormat:(SDLArtworkImageFormat)imageFormat {
++ (NSData *)sdl_dataForUIImage:(UIImage *)image imageFormat:(SDLArtworkImageFormat)imageFormat {
NSData *imageData = nil;
switch (imageFormat) {
case SDLArtworkImageFormatPNG: {
@@ -70,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param imageFormat Whether the image is a PNG or JPG
* @return The file extension for the image format
*/
-- (NSString *)sdl_fileExtensionForImageFormat:(SDLArtworkImageFormat)imageFormat {
++ (NSString *)sdl_fileExtensionForImageFormat:(SDLArtworkImageFormat)imageFormat {
NSString *fileExtension = nil;
switch (imageFormat) {
case SDLArtworkImageFormatPNG: {
@@ -91,7 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param data The data to hash
* @return A MD5 hash of the data
*/
-- (NSString *)sdl_md5HashFromNSData:(NSData *)data {
++ (NSString *)sdl_md5HashFromNSData:(NSData *)data {
if (data == nil) { return nil; }
unsigned char hash[CC_MD5_DIGEST_LENGTH];
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m
index 246273df4..3ad138161 100644
--- a/SmartDeviceLink_Example/Classes/ProxyManager.m
+++ b/SmartDeviceLink_Example/Classes/ProxyManager.m
@@ -173,8 +173,8 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (SDLLifecycleConfiguration *)sdlex_setLifecycleConfigurationPropertiesOnConfiguration:(SDLLifecycleConfiguration *)config {
- SDLArtwork *appIconArt = [SDLArtwork persistentArtworkWithImage:[UIImage imageNamed:@"AppIcon60x60@2x"] name:@"AppIcon" asImageFormat:SDLArtworkImageFormatPNG];
-
+ SDLArtwork *appIconArt = [SDLArtwork persistentArtworkWithImage:[UIImage imageNamed:@"AppIcon60x60@2x"] asImageFormat:SDLArtworkImageFormatPNG];
+
config.shortAppName = @"SDL Example";
config.appIcon = appIconArt;
config.voiceRecognitionCommandNames = @[@"S D L Example"];