FWAsset
@interface FWAsset : NSObject
相册里某一个资源的包装对象,该资源可能是图片、视频等。
Note
FWAsset 重写了 isEqual: 方法,只要两个 FWAsset 的 identifier 相同,则认为是同一个对象,以方便在数组、字典等容器中对大量 FWAsset 进行遍历查找等操作。-
Undocumented
Declaration
Objective-C
@property(nonatomic, assign, readonly) FWAssetType assetType
-
Undocumented
Declaration
Objective-C
@property(nonatomic, assign, readonly) FWAssetSubType assetSubType
-
Undocumented
Declaration
Objective-C
- (instancetype)initWithPHAsset:(PHAsset *)phAsset;
-
Undocumented
Declaration
Objective-C
@property(nonatomic, strong, readonly) PHAsset *phAsset
-
Undocumented
Declaration
Objective-C
@property(nonatomic, assign, readonly) FWAssetDownloadStatus downloadStatus
-
Undocumented
Declaration
Objective-C
@property(nonatomic, assign) double downloadProgress
-
Undocumented
Declaration
Objective-C
@property(nonatomic, assign) NSInteger requestID
-
Undocumented
Declaration
Objective-C
@property(nonatomic, copy, readonly) NSString *identifier
-
Undocumented
Declaration
Objective-C
@property(nullable, nonatomic, strong) UIImage *editedImage
-
Undocumented
Declaration
Objective-C
@property(nullable, nonatomic, strong) id requestObject
-
Undocumented
Declaration
Objective-C
@property(nullable, nonatomic, copy) NSDictionary *requestInfo
-
Asset 的原图(包含系统相册“编辑”功能处理后的效果)
Declaration
Objective-C
- (nullable UIImage *)originImage;
-
Asset 的缩略图
Declaration
Objective-C
- (nullable UIImage *)thumbnailImageWithSize:(CGSize)size;
Parameters
size
指定返回的缩略图的大小,pt 为单位
Return Value
Asset 的缩略图
-
Asset 的预览图
Warning
输出与当前设备屏幕大小相同尺寸的图片,如果图片原图小于当前设备屏幕的尺寸,则只输出原图大小的图片Declaration
Objective-C
- (nullable UIImage *)previewImage;
Return Value
Asset 的全屏图
-
异步请求 Asset 的原图,包含了系统照片“编辑”功能处理后的效果(剪裁,旋转和滤镜等),可能会有网络请求
Declaration
Objective-C
- (NSInteger) requestOriginImageWithCompletion: (nullable void (^)(UIImage *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong, BOOL))completion withProgressHandler: (nullable PHAssetImageProgressHandler)phProgressHandler;
Parameters
completion
完成请求后调用的 block,参数中包含了请求的原图以及图片信息,这个 block 会被多次调用, 其中第一次调用获取到的尺寸很小的低清图,然后不断调用,直到获取到高清图。
phProgressHandler
处理请求进度的 handler,不在主线程上执行,在 block 中修改 UI 时注意需要手工放到主线程处理。
Return Value
返回请求图片的请求 id
-
异步请求 Asset 的缩略图,不会产生网络请求
Declaration
Objective-C
- (NSInteger) requestThumbnailImageWithSize:(CGSize)size completion: (nullable void (^)( UIImage *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong, BOOL))completion;
Parameters
size
指定返回的缩略图的大小
completion
完成请求后调用的 block,参数中包含了请求的缩略图以及图片信息,这个 block 会被多次调用, 其中第一次调用获取到的尺寸很小的低清图,然后不断调用,直到获取到高清图,这时 block 中的第二个参数(图片信息)返回的为 nil。
Return Value
返回请求图片的请求 id
-
异步请求 Asset 的预览图,可能会有网络请求
Declaration
Objective-C
- (NSInteger) requestPreviewImageWithCompletion: (nullable void (^)(UIImage *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong, BOOL))completion withProgressHandler: (nullable PHAssetImageProgressHandler)phProgressHandler;
Parameters
completion
完成请求后调用的 block,参数中包含了请求的预览图以及图片信息,这个 block 会被多次调用, 其中第一次调用获取到的尺寸很小的低清图,然后不断调用,直到获取到高清图。
phProgressHandler
处理请求进度的 handler,不在主线程上执行,在 block 中修改 UI 时注意需要手工放到主线程处理。
Return Value
返回请求图片的请求 id
-
异步请求 Live Photo,可能会有网络请求
Warning
iOS 9.1 以下中并没有 Live Photo,因此无法获取有效结果。
Declaration
Objective-C
- (NSInteger) requestLivePhotoWithCompletion: (nullable void (^)(PHLivePhoto *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong, BOOL))completion withProgressHandler: (nullable PHAssetImageProgressHandler)phProgressHandler;
Parameters
completion
完成请求后调用的 block,参数中包含了请求的 Live Photo 以及相关信息,若 assetType 不是 FWAssetTypeLivePhoto 则为 nil
phProgressHandler
处理请求进度的 handler,不在主线程上执行,在 block 中修改 UI 时注意需要手工放到主线程处理。
Return Value
返回请求图片的请求 id
-
异步请求 AVPlayerItem,可能会有网络请求
Declaration
Objective-C
- (NSInteger) requestPlayerItemWithCompletion: (nullable void (^)(AVPlayerItem *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong)) completion withProgressHandler: (nullable PHAssetVideoProgressHandler)phProgressHandler;
Parameters
completion
完成请求后调用的 block,参数中包含了请求的 AVPlayerItem 以及相关信息,若 assetType 不是 FWAssetTypeVideo 则为 nil
phProgressHandler
处理请求进度的 handler,不在主线程上执行,在 block 中修改 UI 时注意需要手工放到主线程处理。
Return Value
返回请求 AVPlayerItem 的请求 id
-
异步请求 视频文件URL,可能会有网络请求
Declaration
Objective-C
- (NSInteger) requestVideoURLWithOutputURL:(nonnull NSURL *)outputURL exportPreset:(nonnull NSString *)exportPreset completion: (nullable void (^)(NSURL *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong))completion withProgressHandler: (nullable PHAssetVideoProgressHandler)phProgressHandler;
Parameters
outputURL
视频输出文件URL路径,如果路径已存在会导出失败
exportPreset
导出视频选项配置
completion
完成请求后调用的 block,参数中包含了请求的 文件URL 以及相关信息,若 assetType 不是 FWAssetTypeVideo 则为 nil
phProgressHandler
处理请求进度的 handler,不在主线程上执行,在 block 中修改 UI 时注意需要手工放到主线程处理。
Return Value
返回请求 视频文件URL 的请求 id
-
异步请求图片的 Data
Declaration
Objective-C
- (void)requestImageDataWithCompletion: (nullable void (^)(NSData *_Nullable __strong, NSDictionary<NSString *, id> *_Nullable __strong, BOOL, BOOL))completion;
Parameters
completion
完成请求后调用的 block,参数中包含了请求的图片 Data(若 assetType 不是 FWAssetTypeImage 或 FWAssetTypeLivePhoto 则为 nil),该图片是否为 GIF 的判断值,以及该图片的文件格式是否为 HEIC
-
获取图片的 UIImageOrientation 值,仅 assetType 为 FWAssetTypeImage 或 FWAssetTypeLivePhoto 时有效
Declaration
Objective-C
- (UIImageOrientation)imageOrientation;
-
更新下载资源的结果
Declaration
Objective-C
- (void)updateDownloadStatusWithDownloadResult:(BOOL)succeed;
-
获取 Asset 的体积(数据大小)
Declaration
Objective-C
- (void)assetSize:(nullable void (^)(long long))completion;
-
获取 Asset 的总时长(仅视频)
Declaration
Objective-C
- (NSTimeInterval)duration;