Sie sind auf Seite 1von 28

ALAssetsLibrary Class Reference

Contents

ALAssetsLibrary Class Reference 4


Overview 4 Tasks 5 Accessing Assets 5 Managing Notifications 5 Finding Assets 5 Enumerating Assets 5 Saving Assets 5 Managing Asset Groups 6 Class Methods 6 authorizationStatus 6 disableSharedPhotoStreamsSupport 6 Instance Methods 7 addAssetsGroupAlbumWithName:resultBlock:failureBlock: 7 assetForURL:resultBlock:failureBlock: 8 enumerateGroupsWithTypes:usingBlock:failureBlock: 9 groupForURL:resultBlock:failureBlock: 10 videoAtPathIsCompatibleWithSavedPhotosAlbum: 11 writeImageDataToSavedPhotosAlbum:metadata:completionBlock: 11 writeImageToSavedPhotosAlbum:metadata:completionBlock: 12 writeImageToSavedPhotosAlbum:orientation:completionBlock: 13 writeVideoAtPathToSavedPhotosAlbum:completionBlock: 13 Constants 14 ALAssetsGroupType 14 Types of Asset 15 ALAssetOrientation 16 ALAssetsLibraryGroupsEnumerationResultsBlock 17 ALAssetsLibraryAssetForURLResultBlock 18 ALAssetsLibraryWriteImageCompletionBlock 19 ALAssetsLibraryWriteVideoCompletionBlock 19 ALAssetsLibraryAccessFailureBlock 20 ALAssetsLibraryGroupResultBlock 20 ALAuthorizationStatus 21 Notification Keys 22

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

Contents

Error Domain 22 Error Codes 23 Notifications 26 ALAssetsLibraryChangedNotification 26

Document Revision History 27

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference

Inherits from Conforms to Framework Availability Declared in Related sample code

NSObject NSObject (NSObject) /System/Library/Frameworks/AssetsLibrary.framework Available in iOS 4.0 and later. ALAssetsLibrary.h

AVCam AVMovieExporter AVPlayerDemo MyImagePicker PhotosByLocation

Overview
An instance of ALAssetsLibrary provides access to the videos and photos that are under the control of the Photos application. The library includes those that are in the Saved Photos album, those coming from iTunes, and those that were directly imported into the device. You use it to retrieve the list of all asset groups and to save images and videos into the Saved Photos album. You create an instance of ALAssetsLibrary using alloc and init:
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

The lifetimes of objects you get back from a library instance are tied to the lifetime of the library instance. Many of the methods declared by ALAssetsLibrary take blocks for failure and success as arguments. These methods are all asynchronous because the user may need to be asked to grant access to the data.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference Tasks

Tasks
Accessing Assets
+ authorizationStatus

(page 6) Returns photo data authorization status for this application.

Managing Notifications
+ disableSharedPhotoStreamsSupport

(page 6) Disables shared photo streams notifications and asset retrieval.

Finding Assets
assetForURL:resultBlock:failureBlock:

(page 8) Invokes a given block passing as a parameter an asset identified by a specified file URL.

Enumerating Assets
enumerateGroupsWithTypes:usingBlock:failureBlock:

(page 9) Invokes a given block passing as a parameter each of the asset groups that match the given asset group type.

Saving Assets
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

(page 13) Saves a video identified by a given URL to the Saved Photos album. (page 11) Returns a Boolean value that indicates whether a video identified by a given URL is compatible with the Saved Photos album. (page 13) (page 11) Saves a given image to the Saved Photos album.

videoAtPathIsCompatibleWithSavedPhotosAlbum:

writeImageToSavedPhotosAlbum:orientation:completionBlock:

writeImageDataToSavedPhotosAlbum:metadata:completionBlock:

Writes given image data and metadata to the Photos Album.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference Class Methods

writeImageToSavedPhotosAlbum:metadata:completionBlock:

(page 12)

Writes a given image and metadata to the Photos Album.

Managing Asset Groups


addAssetsGroupAlbumWithName:resultBlock:failureBlock:

(page 7)

Adds a new assets group to the library.


groupForURL:resultBlock:failureBlock:

(page 10) Returns an assets group in the result block for a URL previously retrieved from an ALAssetsGroup object.

Class Methods
authorizationStatus
Returns photo data authorization status for this application.
+ (ALAuthorizationStatus)authorizationStatus

Return Value Photo data authorization status for this application. For the constants returned, see ALAuthorizationStatus (page 21). Discussion This method does not prompt the user for access. You can use it to detect restricted access and simply hide UI instead of prompting for access. Availability Available in iOS 6.0 and later. Declared in
ALAssetsLibrary.h

disableSharedPhotoStreamsSupport
Disables shared photo streams notifications and asset retrieval.
+ (void)disableSharedPhotoStreamsSupport

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference Instance Methods

Discussion Shared photo streams can generate frequent notifications. Use this method to disable support if appropriate for your app. Apps compiled against versions of iOS prior to iOS 6.0 do not have support for shared photo streams. Availability Available in iOS 6.0 and later. Declared in
ALAssetsLibrary.h

Instance Methods
addAssetsGroupAlbumWithName:resultBlock:failureBlock:
Adds a new assets group to the library.
- (void)addAssetsGroupAlbumWithName:(NSString *)name

resultBlock:(ALAssetsLibraryGroupResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

Parameters
name

The name for the new group. If name conflicts with another assets group with the same name, then the group is not created and resultBlock returns a nil group.
resultBlock

The block invoked after the add operation completes. For a description of the block, see ALAssetsLibraryAccessFailureBlock (page 20).
failureBlock

The block to invoke if the add operation failsfor example, if the user denies access to the application. For a description of the block, see ALAssetsGroupFaces (page 15). Discussion The name of the new asset group is name, its type is ALAssetsGroupAlbum (page 15), and the editable property is YES.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference Instance Methods

This method is asynchronous. When the assets group is added, the user may be asked to confirm the applications access to the data; the method, though, returns immediately. You should perform whatever work you want with the group in resultBlock. If the user denies access to the application, or if no application is allowed to access the data, or if the data is currently unavailable, the failure block is called. Availability Available in iOS 5.0 and later. Declared in
ALAssetsLibrary.h

assetForURL:resultBlock:failureBlock:
Invokes a given block passing as a parameter an asset identified by a specified file URL.
- (void)assetForURL:(NSURL *)assetURL

resultBlock:(ALAssetsLibraryAssetForURLResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

Parameters
assetURL

An asset URL previously retrieved from an ALAsset object.


resultBlock

The block to invoke using the asset identified by assetURL. For a description of the block, see ALAssetsLibraryAssetForURLResultBlock (page 18).
failureBlock

The block to invoke if the user denies access to the assets library. For a description of the block, see ALAssetsLibraryAccessFailureBlock (page 20). Discussion This method is asynchronous. When the asset is requested, the user may be asked to confirm the application's access to the library; the method, though, returns immediately. You should perform whatever work you want with the asset in resultBlock. If the user denies access to the application, or if no application is allowed to access the data, the failure block is called. Availability Available in iOS 4.0 and later.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference Instance Methods

Related Sample Code

PrintPhoto

Declared in
ALAssetsLibrary.h

enumerateGroupsWithTypes:usingBlock:failureBlock:
Invokes a given block passing as a parameter each of the asset groups that match the given asset group type.
- (void)enumerateGroupsWithTypes:(ALAssetsGroupType)types

usingBlock:(ALAssetsLibraryGroupsEnumerationResultsBlock)enumerationBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

Parameters
types

The types of asset group over which to enumerate. The value is a bitfield; you can OR together values from writeImageDataToSavedPhotosAlbum:metadata:completionBlock: (page 11).
enumerationBlock

The block to invoke using each asset group in turn. When the enumeration is done, enumerationBlock is invoked with group set to nil. For a description of the block, see ALAssetsLibraryGroupsEnumerationResultsBlock (page 17).
failureBlock

The block to invoke if the user denies access to the assets library. For a description of the block, see ALAssetsLibraryAccessFailureBlock (page 20). Discussion The results are passed one by one to the caller by executing the enumeration block. This method is asynchronous. When groups are enumerated, the user may be asked to confirm the application's access to the data; the method, though, returns immediately. You should perform whatever work you want with the assets in enumerationBlock. If the user denies access to the application, or if no application is allowed to access the data, the failureBlock is called. Special Considerations This method will fail with error ALAssetsLibraryAccessGloballyDeniedError (page 25) if the user has not enabled Location Services (in Settings > General).

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

ALAssetsLibrary Class Reference Instance Methods

Availability Available in iOS 4.0 and later.


Related Sample Code

AVMovieExporter AVPlayerDemo MTAudioProcessingTap Audio Processor Declared in


ALAssetsLibrary.h

groupForURL:resultBlock:failureBlock:
Returns an assets group in the result block for a URL previously retrieved from an ALAssetsGroup object.
- (void)groupForURL:(NSURL *)groupURL

resultBlock:(ALAssetsLibraryGroupResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

Parameters
groupURL

The URL for an ALAssetsGroup object.


resultBlock

The block invoked after the access operation completes. For a description of the block, see ALAssetsLibraryAccessFailureBlock (page 20).
failureBlock

The block to invoke if the access operation failsfor example, if the user denies access to the application. For a description of the block, see ALAssetsGroupFaces (page 15). Discussion This method is asynchronous: it returns immediately. You should perform whatever work you want with the assets group in resultBlock. This method is asynchronous. When the assets group is requested, the user may be asked to confirm the applications access to the data; the method, though, returns immediately. You should perform whatever work you want with the asset group in resultBlock. If the user denies access to the application, or if no application is allowed to access the data, or if the data is currently unavailable, the failure block is called.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

10

ALAssetsLibrary Class Reference Instance Methods

Availability Available in iOS 5.0 and later. Declared in


ALAssetsLibrary.h

videoAtPathIsCompatibleWithSavedPhotosAlbum:
Returns a Boolean value that indicates whether a video identified by a given URL is compatible with the Saved Photos album.
- (BOOL)videoAtPathIsCompatibleWithSavedPhotosAlbum:(NSURL *)videoPathURL

Parameters
videoPathURL

An URL that points to a video file. Return Value YES if the video identified by videoPathURL is compatible with the Saved Photos album, otherwise NO. Discussion This method returns the same value as UIVideoAtPathIsCompatibleWithSavedPhotosAlbum would for the same URL. Availability Available in iOS 4.0 and later. See Also
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

(page 13)

Declared in
ALAssetsLibrary.h

writeImageDataToSavedPhotosAlbum:metadata:completionBlock:
Writes given image data and metadata to the Photos Album.
- (void)writeImageDataToSavedPhotosAlbum:(NSData *)imageData metadata:(NSDictionary

*)metadata completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock

Parameters
imageData

Data for the image to add to the album.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

11

ALAssetsLibrary Class Reference Instance Methods

metadata

The metadata to associate with the image.


completionBlock

The block invoked after the save operation completes. For a description of the block, see ALAssetsLibraryWriteImageCompletionBlock (page 19). Discussion If there is a conflict between the metadata in the image data and the metadata dictionary, the image data metadata values will be overwritten. Availability Available in iOS 4.1 and later.
Related Sample Code

SquareCam

Declared in
ALAssetsLibrary.h

writeImageToSavedPhotosAlbum:metadata:completionBlock:
Writes a given image and metadata to the Photos Album.
- (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef metadata:(NSDictionary

*)metadata completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock

Parameters
imageRef

The image to add to the album.


metadata

The metadata to associate with the image.


completionBlock

The block invoked after the save operation completes. For a description of the block, see ALAssetsLibraryWriteImageCompletionBlock (page 19). Discussion You must specify the orientation key in the metadata dictionary to preserve the orientation of the image. Availability Available in iOS 4.1 and later.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

12

ALAssetsLibrary Class Reference Instance Methods

Declared in
ALAssetsLibrary.h

writeImageToSavedPhotosAlbum:orientation:completionBlock:
Saves a given image to the Saved Photos album.
- (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef

orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock

Parameters
imageRef

The image to save to the Saved Photos album.


orientation

The orientation at which to save the image.


completionBlock

The block invoked after the save operation completes. For a description of the block, see ALAssetsLibraryWriteImageCompletionBlock (page 19). Discussion If you want to save a UIImage object, you can use the UIImage method CGImage to get a CGImageRef, and cast the images imageOrientation to ALAssetOrientation. Availability Available in iOS 4.0 and later. See Also
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

(page 13)

Declared in
ALAssetsLibrary.h

writeVideoAtPathToSavedPhotosAlbum:completionBlock:
Saves a video identified by a given URL to the Saved Photos album.
- (void)writeVideoAtPathToSavedPhotosAlbum:(NSURL *)videoPathURL

completionBlock:(ALAssetsLibraryWriteVideoCompletionBlock)completionBlock

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

13

ALAssetsLibrary Class Reference Constants

Parameters
videoPathURL

An URL that points to a video file.


completionBlock

The block invoked after the save operation completes. For a description of the block, see ALAssetsLibraryWriteVideoCompletionBlock (page 19). Discussion Availability Available in iOS 4.0 and later. See Also
videoAtPathIsCompatibleWithSavedPhotosAlbum:

(page 11) (page 13)

writeImageToSavedPhotosAlbum:orientation:completionBlock:

Related Sample Code

AVCam AVMovieExporter AVSimpleEditoriOS RosyWriter StopNGo for iOS Declared in

ALAssetsLibrary.h

Constants
ALAssetsGroupType
A bitfield to identify types of asset.

typedef NSUInteger ALAssetsGroupType;

Discussion For possible values, see Types of Asset (page 15). Availability Available in iOS 4.0 and later.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

14

ALAssetsLibrary Class Reference Constants

Declared in
ALAssetsLibrary.h

Types of Asset
Constants to identify types of asset.

enum { ALAssetsGroupLibrary ALAssetsGroupAlbum ALAssetsGroupEvent ALAssetsGroupFaces ALAssetsGroupSavedPhotos ALAssetsGroupPhotoStream ALAssetsGroupAll };

= = = = = = =

(1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4), (1 << 5), 0xFFFFFFFF,

Constants
ALAssetsGroupLibrary

The Library group that includes all assets that are synced from iTunes. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsGroupAlbum

All the albums created on the device or synced from iTunes, not including Photo Stream or Shared Streams Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsGroupEvent

All events, including those created during Camera Connection Kit import. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsGroupFaces

All the faces albums synced from iTunes. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsGroupSavedPhotos

All the photos in the Camera Roll. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

15

ALAssetsLibrary Class Reference Constants

ALAssetsGroupPhotoStream

The PhotoStream album. In iOS 6.0 and later, this also includes Shared Streams. Available in iOS 5.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsGroupAll

The same as ORing together all the group types except for ALAssetsGroupLibrary. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

ALAssetOrientation
Constants to indicate the orientation of an asset.

typedef enum { ALAssetOrientationUp, ALAssetOrientationDown, ALAssetOrientationLeft, ALAssetOrientationRight, ALAssetOrientationUpMirrored, ALAssetOrientationDownMirrored, ALAssetOrientationLeftMirrored, ALAssetOrientationRightMirrored, } ALAssetOrientation;

Constants
ALAssetOrientationUp

Indicates that the picture is in its default orientation, as shown here. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetOrientationDown

Indicates that the picture has been rotated through 180 degrees with respect to
ALAssetOrientationUp

(page 16), as shown here.

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

16

ALAssetsLibrary Class Reference Constants

ALAssetOrientationLeft

Indicates that the picture has been rotated through 90 degrees counter-clockwise with respect to
ALAssetOrientationUp

(page 16), as shown here.

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetOrientationRight

Indicates that the picture has been rotated through 90 degrees clockwise with respect to
ALAssetOrientationUp

(page 16), as shown here.

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetOrientationUpMirrored

Indicates that the picture has been flipped horizontally with respect to ALAssetOrientationUp (page 16), as shown here. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetOrientationDownMirrored

Indicates that the picture has been rotated through 180 degrees with respect to
ALAssetOrientationUp

(page 16) and then flipped horizontally, as shown here.

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetOrientationLeftMirrored

Indicates that the picture has been rotated through 90 degrees counter-clockwise with respect to
ALAssetOrientationUp

(page 16) and then flipped vertically, as shown here.

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetOrientationRightMirrored

Indicates that the picture has been rotated through 90 degrees clockwise with respect to
ALAssetOrientationUp

(page 16) and then flipped vertically, as shown here.

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

ALAssetsLibraryGroupsEnumerationResultsBlock
Signature for the block executed when a match is found during enumeration using enumerateGroupsWithTypes:usingBlock:failureBlock: (page 9).

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

17

ALAssetsLibrary Class Reference Constants

typedef void (^ALAssetsLibraryGroupsEnumerationResultsBlock)(ALAssetsGroup *group, BOOL *stop);

Discussion The block parameters are defined as follows: group The current asset group in the enumeration. stop A pointer to a boolean value; set the value to YES to stop enumeration. Availability Available in iOS 4.0 and later. Declared in
ALAssetsLibrary.h

ALAssetsLibraryAssetForURLResultBlock
Signature for the block executed if the user has granted access to the caller to access the data managed by the framework in assetForURL:resultBlock:failureBlock: (page 8).

typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);

Discussion The block parameter is defined as follows: asset The asset identified by the URL parameter in assetForURL:resultBlock:failureBlock: (page 8). If the asset is not found, asset is nil. Availability Available in iOS 4.0 and later. Declared in
ALAssetsLibrary.h

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

18

ALAssetsLibrary Class Reference Constants

ALAssetsLibraryWriteImageCompletionBlock
SignaturefortheblockexecutedwhenwriteImageToSavedPhotosAlbum:orientation:completionBlock:(page 13) completes.

typedef void (^ALAssetsLibraryWriteImageCompletionBlock)(NSURL *assetURL, NSError *error);

Discussion The block parameters are defined as follows: assetURL An URL that identifies the saved image file. If the image is not saved, assetURL is nil. error If the image is not saved, an error object that describes the reason for failure, otherwise nil. Availability Available in iOS 4.0 and later. Declared in
ALAssetsLibrary.h

ALAssetsLibraryWriteVideoCompletionBlock
Signature for the block executed when writeVideoAtPathToSavedPhotosAlbum:completionBlock: (page 13) completes.

typedef void (^ALAssetsLibraryWriteVideoCompletionBlock)(NSURL *assetURL, NSError *error);

Discussion The block parameters are defined as follows: assetURL An URL that identifies the saved video file. If the video is not saved, assetURL is nil. error If the video is not saved, an error object that describes the reason for failure, otherwise nil. Availability Available in iOS 4.0 and later.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

19

ALAssetsLibrary Class Reference Constants

Declared in
ALAssetsLibrary.h

ALAssetsLibraryAccessFailureBlock
Signature for the block executed if the user does not grant access to the caller to access the data managed by the framework.

typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);

Discussion The block parameter is defined as follows: error An error object that describes why access to the library failed. This block type is used by assetForURL:resultBlock:failureBlock: (page 8) and enumerateGroupsWithTypes:usingBlock:failureBlock: (page 9). Availability Available in iOS 4.0 and later. Declared in
ALAssetsLibrary.h

ALAssetsLibraryGroupResultBlock
Signature for the block executed if the user grants access to the caller to access the data managed by the framework..

typedef void (^ALAssetsLibraryGroupResultBlock)(ALAssetsGroup *group));

Discussion The block parameter is defined as follows: group The group that was added to the assets library. If the group is not found or not created (for example, because of a name collision), group is nil.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

20

ALAssetsLibrary Class Reference Constants

This block type is used by addAssetsGroupAlbumWithName:resultBlock:failureBlock: (page 7) and groupForURL:resultBlock:failureBlock: (page 10). Availability Available in iOS 5.0 and later. Declared in
ALAssetsLibrary.h

ALAuthorizationStatus
Constants to indicate authorization status.

typedef NS_ENUM(NSInteger, ALAuthorizationStatus) { ALAuthorizationStatusNotDetermined = 0, ALAuthorizationStatusRestricted, ALAuthorizationStatusDenied, ALAuthorizationStatusAuthorized };

Constants
ALAuthorizationStatusNotDetermined

User has not yet made a choice with regards to this application. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.
ALAuthorizationStatusRestricted

This application is not authorized to access photo data. The user cannot change this applications status, possibly due to active restrictions such as parental controls being in place. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.
ALAuthorizationStatusDenied

User has explicitly denied this application access to photos data. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.
ALAuthorizationStatusAuthorized

User has authorized this application to access photos data. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

21

ALAssetsLibrary Class Reference Constants

Notification Keys
Keysusedtogetvaluesfromtheuserinformationdictionaryofthe ALAssetsLibraryChangedNotification (page 26) notification.

NSString NSString NSString NSString

* * * *

const const const const

ALAssetLibraryUpdatedAssetsKey; ALAssetLibraryInsertedAssetGroupsKey; ALAssetLibraryUpdatedAssetGroupsKey; ALAssetLibraryDeletedAssetGroupsKey;

Constants
ALAssetLibraryUpdatedAssetsKey

Value is a set of NSURL objects identifying the assets that were updated. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.
ALAssetLibraryInsertedAssetGroupsKey

Value is a set of NSURL objects identifying the assets that were inserted. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.
ALAssetLibraryUpdatedAssetGroupsKey

Value is a set of NSURL objects identifying the asset groups that were updated. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h.
ALAssetLibraryDeletedAssetGroupsKey

Value is a set of NSURL objects identifying the asset groups that were deleted. Available in iOS 6.0 and later. Declared in ALAssetsLibrary.h. Discussion Assets that are modified use the ALAssetLibraryUpdatedAssetsKey key. Assets that are inserted or deleted use the ALAssetLibraryUpdatedAssetGroupsKey key for the asset group that contains the asset. Assets and asset groups that have no strong references are omitted from the notifications user information dictionary.

Error Domain
Constant for the AssetsLibrary domain.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

22

ALAssetsLibrary Class Reference Constants

NSString *const ALAssetsLibraryErrorDomain;

Constants
ALAssetsLibraryErrorDomain

Constant used by NSError to distinguish errors belonging to the AssetsLibrary domain. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

Error Codes
AssetsLibrary-related error codes

enum { ALAssetsLibraryUnknownError =

-1,

ALAssetsLibraryWriteFailedError = -3300, ALAssetsLibraryWriteBusyError = -3301, ALAssetsLibraryWriteInvalidDataError = -3302, ALAssetsLibraryWriteIncompatibleDataError = -3303, ALAssetsLibraryWriteDataEncodingError = -3304, ALAssetsLibraryWriteDiskSpaceError = -3305, ALAssetsLibraryDataUnavailableError = ALAssetsLibraryAccessUserDeniedError = ALAssetsLibraryAccessGloballyDeniedError = }; -3310, -3311, -3312,

Constants
ALAssetsLibraryUnknownError

The reason for the error is unknown. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsLibraryWriteFailedError

The attempt to write data failed. This error may be returned in the completion block for (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) as well as the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum.
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

23

ALAssetsLibrary Class Reference Constants

ALAssetsLibraryWriteBusyError

Writing was already busy when the attempt to write was made. You should attempt the write again. This error may be returned in the completion block for (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) as well as the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum.
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetsLibraryWriteInvalidDataError

The data was invalid. This error may be returned in the completion block for (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) as well as the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum.
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetsLibraryWriteIncompatibleDataError

The data contained incompatible data. This error may be returned in the completion block for (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) as well as the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum.
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetsLibraryWriteDataEncodingError

The data contained data with the wrong encoding. This error may be returned in the completion block for (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) as well as the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum.
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

24

ALAssetsLibrary Class Reference Constants

ALAssetsLibraryWriteDiskSpaceError

There was not enough space on the disk to write the data. This error may be returned in the completion block for (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) as well as the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum.
writeVideoAtPathToSavedPhotosAlbum:completionBlock:

Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.


ALAssetsLibraryDataUnavailableError

The data was not available. This error may be returned in the ALAssetsLibraryAccessFailureBlock (page 20) for enumerateGroupsWithTypes:usingBlock:failureBlock: (page 9) and assetForURL:resultBlock:failureBlock: (page 8); and in the completion blocks for writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13) and writeImageToSavedPhotosAlbum:orientation:completionBlock: (page 13); as well as in the completion selector for UIImageWriteToSavedPhotosAlbum and UISaveVideoAtPathToSavedPhotosAlbum. Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsLibraryAccessUserDeniedError

The user denied access to the library. This error may be returned in the ALAssetsLibraryAccessFailureBlock (page 20) block for enumerateGroupsWithTypes:usingBlock:failureBlock: (page 9) and assetForURL:resultBlock:failureBlock: (page 8). Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.
ALAssetsLibraryAccessGloballyDeniedError

Access to the library was denied globally. This error may be returned in the ALAssetsLibraryAccessFailureBlock (page 20) block for enumerateGroupsWithTypes:usingBlock:failureBlock: (page 9) and assetForURL:resultBlock:failureBlock: (page 8). Available in iOS 4.0 and later. Declared in ALAssetsLibrary.h.

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

25

ALAssetsLibrary Class Reference Notifications

Notifications
ALAssetsLibraryChangedNotification
Sent when the contents of the assets library have changed from under the app that is using the data. In iOS 4.0, the notifications object is nil. In iOS 4.1 and later, the notification object is the library object that posted the notification. In iOS 6.0 and later, the user information dictionary describes what changed: If the user information dictionary is nil, reload all assets and asset groups.

If the user information dictionary an empty dictionary, there is no need to reload assets and asset groups. If the user information dictionary is not empty, reload the effected assets and asset groups. For the keys used, see Notification Keys (page 22).

This notification is sent on an arbitrary thread. Availability Available in iOS 4.0 and later. Declared in
ALAssetsLibrary.h

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

26

Document Revision History

This table describes the changes to ALAssetsLibrary Class Reference .

Date 2012-12-13 2012-09-19 2011-10-12 2011-04-28

Notes Added to the discussion of ALAssetsLibraryAccessGloballyDeniedError. Updated with API to support data privacy. Updated for iOS v5.0. Noted that enumerateGroupsWithTypes:usingBlock:failureBlock: fails if the user has not enabled Location Services. Updated for iOS v4. First version of a document that describes the object that represents the videos and photos in the Photos application.

2010-07-01 2010-05-24

2012-12-13 | Copyright 2012 Apple Inc. All Rights Reserved.

27

Apple Inc. Copyright 2012 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apples copyright notice. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, and iTunes are trademarks of Apple Inc., registered in the U.S. and other countries. iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED AS IS, AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.