ADPhotoKit Documentation

Class ADPhoto​Manager

public class ADPhotoManager  

Main manager class of ADPhotoKit Core. It provide a set of convenience methods to fetch asset from system album. You can use this class to fetch or save asset.

Nested Types

ADPhotoManager.AssetResultType

Type of fetch result.

Nested Type Aliases

ADAsset​Progress​Handler

public typealias ADAssetProgressHandler = (Double, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void

Provide caller a way to be told how much progress has been made prior to delivering the data when it comes from iCloud.

ADAsset​Completion​Handler

public typealias ADAssetCompletionHandler = (Any?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch complete.

ADImage​Completion​Handler

public typealias ADImageCompletionHandler = (UIImage?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch image complete.

ADData​Completion​Handler

public typealias ADDataCompletionHandler = (Data?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch data complete.

ADLive​Photo​Completion​Handler

public typealias ADLivePhotoCompletionHandler = (PHLivePhoto?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch livePhoto complete.

ADPlay​Item​Completion​Handler

public typealias ADPlayItemCompletionHandler = (AVPlayerItem?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch playItem complete.

ADAVAssert​Completion​Handler

public typealias ADAVAssertCompletionHandler = (AVAsset?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch AVAsset complete.

ADFile​Path​Completion​Handler

public typealias ADFilePathCompletionHandler = (String?, [AnyHashable: Any]?, Bool) -> Void

A block that is called after fetch file path complete.

Methods

all​Photo​Album​List(options:​completion:​)

public class func allPhotoAlbumList(options: ADAlbumSelectOptions = .default, completion: (([ADAlbumModel]) -> Void))  

Fetch all album.

Parameters

options ADAlbum​Select​Options

Options to set the album type and order. It is ADAlbumSelectOptions.default by default.

completion (([ADAlbum​Model]) -> Void)

Called after finish fetching.

camera​Roll​Album(options:​completion:​)

public class func cameraRollAlbum(options: ADAlbumSelectOptions = .default, completion: @escaping ( (ADAlbumModel) -> Void ))  

Fetch cameraRoll album.

Parameters

options ADAlbum​Select​Options

Options to set the album type and order. It is ADAlbumSelectOptions.default by default.

completion @escaping ( (ADAlbum​Model) -> Void )

Called after finish fetching.

fetch​Assets(in:​options:​limit​Count:​)

public class func fetchAssets(in result: PHFetchResult<PHAsset>, options: ADAlbumSelectOptions = .default, limitCount: Int = .max) -> [ADAssetModel]  

Fetch assets in album.

Parameters

result PHFetch​Result<PHAsset>

Fetch result associate with album.

options ADAlbum​Select​Options

Options to set the album type and order. It is ADAlbumSelectOptions.default by default.

limit​Count Int

Max count to fetch.

Returns

Assets in album.

fetch(for:​type:​progress:​completion:​)

@discardableResult
    public class func fetch(for asset: PHAsset, type: AssetResultType, progress: ADAssetProgressHandler? = nil, completion: @escaping ADAssetCompletionHandler) -> PHImageRequestID?  

Fetch assset's data by type.

Parameters

asset PHAsset

Asset to fetch result.

type Asset​Result​Type

Type of fetch result.

progress ADAsset​Progress​Handler?

Progress of fetching request.

completion @escaping ADAsset​Completion​Handler

Called after fetch result.

Returns

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest: method.

fetch​Image(for:​size:​resize​Mode:​synchronous:​progress:​completion:​)

@discardableResult
    public class func fetchImage(for asset: PHAsset, size: CGSize? = nil, resizeMode: PHImageRequestOptionsResizeMode = .fast, synchronous: Bool = false, progress: PHAssetImageProgressHandler? = nil, completion: @escaping ADImageCompletionHandler) -> PHImageRequestID  

Fetch image for asset.

Parameters

asset PHAsset

Asset to fetch result.

size CGSize?

Size of the image fetch, If nil, will fetch original image.

resize​Mode PHImage​Request​Options​Resize​Mode

Image resize mode.

synchronous Bool

Return only a single result, blocking until available (or failure).

progress PHAsset​Image​Progress​Handler?

Progress of fetching request.

completion @escaping ADImage​Completion​Handler

Called after fetch result.

Returns

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest: method.

fetch​Origin​Image​Data(for:​progress:​completion:​)

@discardableResult
    public class func fetchOriginImageData(for asset: PHAsset, progress: PHAssetImageProgressHandler? = nil, completion: @escaping ADDataCompletionHandler) -> PHImageRequestID  

Fetch origin data for asset.

Parameters

asset PHAsset

Asset to fetch result.

progress PHAsset​Image​Progress​Handler?

Progress of fetching request.

completion @escaping ADData​Completion​Handler

Called after fetch result.

Returns

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest: method.

fetch​Live​Photo(for:​progress:​completion:​)

@discardableResult
    public class func fetchLivePhoto(for asset: PHAsset, progress: PHAssetImageProgressHandler? = nil, completion: @escaping ADLivePhotoCompletionHandler) -> PHImageRequestID  

Fetch livePhoto for asset.

Parameters

asset PHAsset

Asset to fetch result.

progress PHAsset​Image​Progress​Handler?

Progress of fetching request.

completion @escaping ADLive​Photo​Completion​Handler

Called after fetch result.

Returns

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest: method.

fetch​Video(for:​progress:​completion:​)

@discardableResult
    public class func fetchVideo(for asset: PHAsset, progress: PHAssetImageProgressHandler? = nil, completion: @escaping ADPlayItemCompletionHandler) -> PHImageRequestID  

Fetch video for asset.

Parameters

asset PHAsset

Asset to fetch result.

progress PHAsset​Image​Progress​Handler?

Progress of fetching request.

completion @escaping ADPlay​Item​Completion​Handler

Called after fetch result.

Returns

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest: method.

fetch​AVAsset(for​Video:​progress:​completion:​)

@discardableResult
    public class func fetchAVAsset(forVideo asset: PHAsset, progress: PHAssetImageProgressHandler? = nil, completion: @escaping ADAVAssertCompletionHandler) -> PHImageRequestID  

Fetch AVAsset for asset.

Parameters

asset PHAsset

Asset to fetch result.

progress PHAsset​Image​Progress​Handler?

Progress of fetching request.

completion @escaping ADAVAssert​Completion​Handler

Called after fetch result.

Returns

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest: method.

fetch​File​Path(asset:​completion:​)

public class func fetchFilePath(asset: PHAsset, completion: @escaping ADFilePathCompletionHandler)  

Fetch file path for asset.

Parameters

asset PHAsset

Asset to fetch result.

completion @escaping ADFile​Path​Completion​Handler

Called after fetch result.

save​Image​ToAlbum(image:​completion:​)

public class func saveImageToAlbum(image: UIImage, completion: ( (Bool, PHAsset?) -> Void )? )  

Save image to album.

Parameters

image UIImage

Image to save.

completion ( (Bool, PHAsset?) -> Void )?

Called after image saved.

save​Video​ToAlbum(url:​completion:​)

public class func saveVideoToAlbum(url: URL, completion: ( (Bool, PHAsset?) -> Void )? )  

Save video to album.

Parameters

url URL

Video asset's path.

completion ( (Bool, PHAsset?) -> Void )?

Called after video saved.

photo​Authority()

public class func photoAuthority() -> Bool  

Check authority access to system album.

Returns

If have authority.