iOS Developer Library

Developer

AssetsLibrary Framework Reference ALAsset Class Reference

Options
Deployment Target:

On This Page
Language:

ALAsset

An ALAsset object represents a photo or a video managed by the Photo application. More...

Inheritance


Conforms To


Import Statement


import AssetsLibrary @import AssetsLibrary;

Availability


Available in iOS 4.0 and later.
  • Returns the value for a given property.

    Declaration

    Swift

    func valueForProperty(_ property: String!) -> AnyObject!

    Objective-C

    - (id)valueForProperty:(NSString *)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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • editable editable Property

    Indicates whether the asset is editable. (read-only)

    Declaration

    Swift

    var editable: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isEditable) BOOL editable

    Discussion

    The property value is YEStrue if the application is able to edit the asset, and NOfalse if the application is not able to edit the asset. Applications are only allowed to edit assets that they originally wrote.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

  • The original version of the asset. (read-only)

    Declaration

    Swift

    var originalAsset: ALAsset! { get }

    Objective-C

    @property(nonatomic, readonly) ALAsset *originalAsset

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

  • Returns an asset representation object for the default representation.

    Declaration

    Swift

    func defaultRepresentation() -> ALAssetRepresentation!

    Objective-C

    - (ALAssetRepresentation *)defaultRepresentation

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • Returns an an asset representation object for a given representation UTI.

    Declaration

    Swift

    func representationForUTI(_ representationUTI: String!) -> ALAssetRepresentation!

    Objective-C

    - (ALAssetRepresentation *)representationForUTI:(NSString *)representationUTI

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • Returns a thumbnail representation of the asset.

    Declaration

    Swift

    func thumbnail() -> Unmanaged<CGImage>!

    Objective-C

    - (CGImageRef)thumbnail

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • Returns an aspect ratio thumbnail of the asset.

    Declaration

    Swift

    func aspectRatioThumbnail() -> Unmanaged<CGImage>!

    Objective-C

    - (CGImageRef)aspectRatioThumbnail

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

  • Replaces the image data in the receiver with given image data

    Declaration

    Swift

    func setImageData(_ imageData: NSData!, metadata metadata: [NSObject : AnyObject]!, completionBlock completionBlock: ALAssetsLibraryWriteImageCompletionBlock!)

    Objective-C

    - (void)setImageData:(NSData *)imageData metadata:(NSDictionary *)metadata completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock

    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 nil asset URL and an ALAssetsLibraryWriteFailedError.

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

  • Replaces the video data in receiver with the video at a given URL.

    Declaration

    Swift

    func setVideoAtPath(_ videoPathURL: NSURL!, completionBlock completionBlock: ALAssetsLibraryWriteVideoCompletionBlock!)

    Objective-C

    - (void)setVideoAtPath:(NSURL *)videoPathURL completionBlock:(ALAssetsLibraryWriteVideoCompletionBlock)completionBlock

    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 nil asset URL and an ALAssetsLibraryWriteFailedError.

    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.

    Import Statement

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

  • Constants for the keys for the properties you can get from an asset.

    Declaration

    Swift

    let ALAssetPropertyType: NSString! let ALAssetPropertyLocation: NSString! let ALAssetPropertyDuration: NSString! let ALAssetPropertyOrientation: NSString! let ALAssetPropertyDate: NSString! let ALAssetPropertyRepresentations: NSString! let ALAssetPropertyURLs: NSString! let ALAssetPropertyAssetURL: NSString!

    Objective-C

    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

    • ALAssetPropertyType

      ALAssetPropertyType

      A key to retrieve the type of the asset.

      Possible values are given in Asset Types.

      Available in iOS 4.0 and later.

    • ALAssetPropertyLocation

      ALAssetPropertyLocation

      The key to retrieve the location information of the asset.

      The corresponding value is a CLLocation object. This is only available if location services are enabled for the caller.

      Available in iOS 4.0 and later.

    • ALAssetPropertyDuration

      ALAssetPropertyDuration

      The key to retrieve the play time duration of a video asset.

      The corresponding value is a double wrapped in an NSNumber object. For photos, ALErrorInvalidProperty is returned.

      Available in iOS 4.0 and later.

    • ALAssetPropertyOrientation

      ALAssetPropertyOrientation

      The key to retrieve the orientation of the asset.

      The corresponding value is an NSNumber object containing an asset's orientation as described by the TIFF format.

      Available in iOS 4.0 and later.

    • ALAssetPropertyDate

      ALAssetPropertyDate

      The key to retrieve the creation date of the asset.

      The corresponding value is an NSDate object.

      Available in iOS 4.0 and later.

    • ALAssetPropertyRepresentations

      ALAssetPropertyRepresentations

      The key to retrieve the representations available for a given asset (for example RAW, JPEG).

      The corresponding value is an NSArray object containing UTIs expressed as strings.

      Available in iOS 4.0 and later.

    • ALAssetPropertyURLs

      ALAssetPropertyURLs

      The key to retrieve a dictionary that maps asset representations UTIs to URLs that uniquely identify the asset.

      The corresponding value is an NSDictionary object.

      Available in iOS 4.0 and later.

    • ALAssetPropertyAssetURL

      ALAssetPropertyAssetURL

      The key to retrieve a URL identifier for the asset.

      The corresponding value is an NSURL object.

      This URL is used by the library-change notifications to identify assets and asset groups. Only the ALAssetRepresentation and ALAssetsGroup classes support this property.

      Available in iOS 6.0 and later.

    Import Statement

  • A constant to indicate that a property accessed by valueForProperty: is invalid.

    Declaration

    Swift

    let ALErrorInvalidProperty: NSString!

    Objective-C

    NSString *const ALErrorInvalidProperty;

    Constants

    • ALErrorInvalidProperty

      ALErrorInvalidProperty

      Value returned by valueForProperty: if the property you tried to access is invalid.

      Available in iOS 4.0 and later.

    Import Statement

  • Constants that specify the type of an asset.

    Declaration

    Swift

    let ALAssetTypePhoto: NSString! let ALAssetTypeVideo: NSString! let ALAssetTypeUnknown: NSString!

    Objective-C

    NSString *const ALAssetTypePhoto; NSString *const ALAssetTypeVideo; NSString *const ALAssetTypeUnknown;

    Constants

    • ALAssetTypePhoto

      ALAssetTypePhoto

      Specifies that the asset is a photo.

      Available in iOS 4.0 and later.

    • ALAssetTypeVideo

      ALAssetTypeVideo

      Specifies that the asset is a video.

      Available in iOS 4.0 and later.

    • ALAssetTypeUnknown

      ALAssetTypeUnknown

      Specifies 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.

    Discussion

    These constants represent the values you may get back for the ALAssetPropertyType property.

    Import Statement