Inherits from CDAResource : NSObject
Declared in CDAAsset.h

Overview

Assets represent files in a Space. An asset can be any kind of file: an image, a video, an audio file, a PDF or any other filetype. Assets are usually attached to Entries through Links.

Assets can optionally be localized by providing separate files for each locale. Those Assets which are not localized simply provide a single file under the default locale.

When querying the Content Delivery API for Entries which contain Links to Assets then all Assets will be included by default.

Resize image assets on the fly by supplying the desired dimensions as query parameters.

Tasks

Accessing the URL

Accessing Localized Content

Accessing Meta-Data

  •   fields

    All fields associated with this asset.

    property
  •   isImage

    Returns YES if this asset is referencing an image file, NO otherwise.

    property
  •   MIMEType

    File type of the asset.

    property
  •   size

    Size of the asset, if it is an image.

    property

Creating and Accessing Cached Data

Properties

MIMEType

@property (nonatomic, readonly) NSString *MIMEType
Discussion

File type of the asset.

Declared In

CDAAsset.h

URL

@property (nonatomic, readonly) NSURL *URL
Discussion

The URL with which the asset was initialized. (read-only).

Declared In

CDAAsset.h

fields

@property (nonatomic, readonly) NSDictionary *fields
Discussion

All fields associated with this asset.

Declared In

CDAAsset.h

isImage

@property (nonatomic, readonly) BOOL isImage
Discussion

Returns YES if this asset is referencing an image file, NO otherwise.

Declared In

CDAAsset.h

locale

@property (nonatomic) NSString *locale
Discussion

Locale to be used for accessing any values of fields.

By default, this will be set to the Space’s default locale. If set to a non-existing locale, it will automatically revert to the default value.

Changing this property only has an effect if the receiver was obtained from a CDASyncedSpace originally. Assets obtained any other way will only contain values for the locale specified in the query or for the default locale. In addition to that, this properties value will also only be accurate for Assets obtained from a CDASyncedSpaceoriginally.

Declared In

CDAAsset.h

size

@property (nonatomic, readonly) CGSize size
Discussion

Size of the asset, if it is an image.

Declared In

CDAAsset.h

Class Methods

cachePersistedAsset:client:forcingOverwrite:completionHandler:

+ (void)cachePersistedAsset:(id<CDAPersistedAsset>)persistedAsset client:(CDAClient *)client forcingOverwrite:(BOOL)forceOverwrite completionHandler:(void ( ^ ) ( BOOL success ))handler
Discussion

Cache the data of an Asset to disk.

Parameters

persistedAsset

The Asset whose cached data should be cached.

client

The client to use for Contentful requests.

forceOverwrite

If NO and file already exists, nothing will be done.

handler

This block will be called after persisting the asset.

Declared In

CDAAsset.h

cachedDataForAsset:

+ (NSData *)cachedDataForAsset:(CDAAsset *)asset
Discussion

Access previously cached data for an Asset.

Parameters

asset

The Asset whose cached data should be accessed.

Return Value

Cached data or nil if none was found.

Declared In

CDAAsset.h

cachedDataForPersistedAsset:client:

+ (NSData *)cachedDataForPersistedAsset:(id<CDAPersistedAsset>)persistedAsset client:(CDAClient *)client
Discussion

Access previously cached data for an Asset.

Parameters

persistedAsset

The Asset whose cached data should be accessed.

client

The client to use for Contentful requests.

Return Value

Cached data or nil if none was found.

Declared In

CDAAsset.h

Instance Methods

imageURLWithSize:

- (NSURL *)imageURLWithSize:(CGSize)size
Discussion

URL for retrieving an image asset which is being resized by the server.

If the asset is not refering an image, this method will return the same the URL property.

Parameters

size

The desired size of the output image.

Return Value

An URL for retrieving the resized image.

Declared In

CDAAsset.h

imageURLWithSize:quality:format:

- (NSURL *)imageURLWithSize:(CGSize)size quality:(CGFloat)quality format:(CDAImageFormat)format
Discussion

URL for retrieving an image asset which is being processed by the server.

If the asset is not refering an image, this method will return the same the URL property.

Parameters

size

The desired size of the output image.

quality

The desired quality, with a range from 0.01 to 1.0. Only supported for JPEGs.

format

The desired output format or CDAImageFormatOriginal if it should not be changed.

Return Value

An URL for retrieving the processed image.

Declared In

CDAAsset.h

imageURLWithSize:quality:format:fit:focus:radius:background:progressive:

- (NSURL *)imageURLWithSize:(CGSize)size quality:(CGFloat)quality format:(CDAImageFormat)format fit:(CDAFitType)fit focus:(NSString *)focus radius:(CGFloat)radius background:(NSString *)backgroundColor progressive:(BOOL)progressive
Discussion

URL for retrieving an image asset which is being processed by the server.

If the asset is not refering an image, this method will return the same the URL property.

Parameters

size

The desired size of the output image.

quality

The desired quality, with a range from 0.01 to 1.0. Only supported for JPEGs.

format

The desired output format or CDAImageFormatOriginal if it should not be changed.

fit

Modify the resizing behaviour (CDAFitDefault for default)

focus

Specify the focused area of resizing, this can be: 1. ‘top’, ‘right’, ‘left’, ‘bottom’ 2. A combination like ‘bottom_right’ 3. ‘face’ or ‘faces’ to focus the resizing via face detection 4. nil to use the default

radius

Radius for rounded corners, optionally crop a circle/elipsis via CDARadiusMaximum. The default is CDARadiusNone for not rounding corners.

backgroundColor

Background color, relevant if the fit type CDAFitPad is used. Color constant like ‘blue’ or RGB values like ‘rgb:9090ff’. Default: nil for transparency.

progressive

Deliver a progressive image, only supported for JPEGs.

Return Value

An URL for retrieving the processed image.

Declared In

CDAAsset.h