ALAsset Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AssetsLibrary.framework |
| Availability | Available in iOS 4.0 and later. |
| Declared in | ALAsset.h |
Overview
An ALAsset object represents a photo or a video managed by the Photo application.
Assets can have multiple representations, for example a photo which was captured in RAW and JPG. Different representations of the same asset may have different dimensions.
Tasks
Asset Properties
-
– valueForProperty: -
editableproperty -
originalAssetproperty
Accessing Representations
Setting New Image and Video Data
Saving to the Saved Photos Album
Properties
editable
Indicates whether the asset is editable. (read-only)
Discussion
The property value is YES if the application is able to edit the asset, and NO if the application is not able to edit the asset. Applications are only allowed to edit assets that they originally wrote.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.horiginalAsset
The original version of the asset. (read-only)
Discussion
The property value is the original asset if the receiver was saved as a modified version of an asset. The property value is nil if the asset was not saved as a modified version of another asset.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.hInstance Methods
aspectRatioThumbnail
Returns an aspect ratio thumbnail of the asset.
Return Value
An aspect ratio thumbnail of the asset.
Discussion
Returns a CGImage with an aspect ratio thumbnail of the asset. The size of the thumbnail is the appropriate size for the platform, and in the correct orientation.
This method returns NULL for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.hdefaultRepresentation
Returns an asset representation object for the default representation.
Return Value
An asset representation object for the default representation.
Discussion
This method returns nil for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
Availability
- Available in iOS 4.0 and later.
Declared In
ALAsset.hrepresentationForUTI:
Returns an an asset representation object for a given representation UTI.
Parameters
- representationUTI
A UTI describing a representation for the asset.
Return Value
An an asset representation object for the representation specified by representationUTI, or nil if the asset does not support the representation.
Discussion
This method returns nil for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
Availability
- Available in iOS 4.0 and later.
Declared In
ALAsset.hsetImageData:metadata:completionBlock:
Replaces the image data in the receiver with given image data
Parameters
- imageData
Image data for the asset.
- metadata
Metadata for the image.
- completionBlock
The block invoked after the save operation completes.
If the application is able to edit the asset, the completion block returns the same asset URL as the receiver, because a new asset is not created.
If the application is not able to edit the asset, the completion blocks return a
nilasset URL and anALAssetsLibraryWriteFailedError.
Discussion
Before invoking this method, you should check the editable property of the asset to determine whether it is possible to replace the image data.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.hsetVideoAtPath:completionBlock:
Replaces the video data in receiver with the video at a given URL.
Parameters
- videoPathURL
An URL that specifies the location of video data.
- completionBlock
The block invoked after the save operation completes.
If the application is able to edit the asset, the completion block returns the same asset URL as the receiver, because a new asset is not created.
If the application is not able to edit the asset, the completion blocks return a
nilasset URL and anALAssetsLibraryWriteFailedError.
Discussion
Before invoking this method, you should check the editable property of the asset to determine whether it is possible to replace the video data.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.hthumbnail
Returns a thumbnail representation of the asset.
Return Value
A thumbnail representation of the asset.
Discussion
The size of the thumbnail is the appropriate for the platform. The image is returned in the correct orientation (that is, “pointing up”—you shouldn’t have to rotate the image).
This method returns NULL for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
Availability
- Available in iOS 4.0 and later.
Declared In
ALAsset.hvalueForProperty:
Returns the value for a given property.
Parameters
- property
The property for which you want the value. For valid keys, see “Property Keys.”
Return Value
The value for property. If property is not a valid key, returns ALErrorInvalidProperty.
Availability
- Available in iOS 4.0 and later.
Declared In
ALAsset.hwriteModifiedImageDataToSavedPhotosAlbum:metadata:completionBlock:
Saves image data to the Saved Photos album.
Parameters
- imageData
Image data for the asset.
- metadata
Metadata for the image.
- completionBlock
The block invoked after the save operation completes.
Discussion
This method saves imageData to the saved photos album as a new asset that is considered a modified version of the receiver.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.hwriteModifiedVideoAtPathToSavedPhotosAlbum:completionBlock:
Saves the video at a specified path to the Saved Photos album.
Parameters
- videoPathURL
An URL that specifies the location of video data.
- completionBlock
The block invoked after the save operation completes.
Discussion
This method saves the video at videoPathURL to the Saved Photos album as a new asset that is considered a modified version of the receiver.
Availability
- Available in iOS 5.0 and later.
Declared In
ALAsset.hConstants
Property Keys
Constants for the keys for the properties you can get from an asset.
NSString *const ALAssetPropertyType; NSString *const ALAssetPropertyLocation; NSString *const ALAssetPropertyDuration; NSString *const ALAssetPropertyOrientation; NSString *const ALAssetPropertyDate; NSString *const ALAssetPropertyRepresentations; NSString *const ALAssetPropertyURLs; NSString *const ALAssetPropertyAssetURL;
Constants
ALAssetPropertyTypeA key to retrieve the type of the asset.
Possible values are given in “Asset Types.”
Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyLocationThe key to retrieve the location information of the asset.
The corresponding value is a
CLLocationobject. This is only available if location services are enabled for the caller.Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyDurationThe key to retrieve the play time duration of a video asset.
The corresponding value is a double wrapped in an
NSNumberobject. For photos,ALErrorInvalidPropertyis returned.Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyOrientationThe key to retrieve the orientation of the asset.
The corresponding value is an
NSNumberobject containing an asset's orientation as described by the TIFF format.Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyDateThe key to retrieve the creation date of the asset.
The corresponding value is an
NSDateobject.Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyRepresentationsThe key to retrieve the representations available for a given asset (for example RAW, JPEG).
The corresponding value is an
NSArrayobject containing UTIs expressed as strings.Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyURLsThe key to retrieve a dictionary that maps asset representations UTIs to URLs that uniquely identify the asset.
The corresponding value is an
NSDictionaryobject.Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetPropertyAssetURLThe key to retrieve a URL identifier for the asset.
The corresponding value is an
NSURLobject.This URL is used by the library-change notifications to identify assets and asset groups. Only the
ALAssetRepresentationandALAssetsGroupclasses support this property.Available in iOS 6.0 and later.
Declared in
ALAsset.h.
Invalid Property Value
A constant to indicate that a property accessed by valueForProperty: is invalid.
NSString *const ALErrorInvalidProperty;
Constants
ALErrorInvalidPropertyValue returned by
valueForProperty:if the property you tried to access is invalid.Available in iOS 4.0 and later.
Declared in
ALAsset.h.
Asset Types
Constants that specify the type of an asset.
NSString *const ALAssetTypePhoto; NSString *const ALAssetTypeVideo; NSString *const ALAssetTypeUnknown;
Constants
ALAssetTypePhotoSpecifies that the asset is a photo.
Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetTypeVideoSpecifies that the asset is a video.
Available in iOS 4.0 and later.
Declared in
ALAsset.h.ALAssetTypeUnknownSpecifies that the asset's type cannot be determined.
The asset could be a sound file, a video or photo file that the system doesn’t know about or something else. This is possible only for assets imported from a camera onto the device.
Available in iOS 4.0 and later.
Declared in
ALAsset.h.
Discussion
These constants represent the values you may get back for the ALAssetPropertyType property.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)