更多来源:iOS系统相册的使用
+ (void)checkSystemAssetInCloud:(PHAsset *)asset complet:(void(^)(BOOL isInCloud))complet {
//视频类型 if (asset.mediaType == PHAssetMediaTypeVideo) {
// 请求视频资源 [[PHImageManager defaultManager] requestExportSessionForVideo:asset options:nil exportPreset:AVAssetExportPresetHighestQuality resultHandler:^(AVAssetExportSession * _Nullable exportSession, NSDictionary * _Nullable info) {
// 获取的info中 PHImageResultIsInCloudKey 对应是否云存储 dispatch_async(dispatch_get_main_queue(), ^{
complet ? complet([info[PHImageResultIsInCloudKey] intValue] && !exportSession) : nil;
});
}];
}
// 图片类型 if (asset.mediaType == PHAssetMediaTypeImage) {
// 创建图片请求的option PHImageRequestOptions *originOptions = [[PHImageRequestOptions alloc]init];
// 初始化相关的值 originOptions.version = PHImageRequestOptionsVersionOriginal;
originOptions.resizeMode = PHImageRequestOptionsResizeModeNone;
originOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
// ios 13之后 if (@available(iOS 13, *)) {
// 通过option请求图片资源 [[PHImageManager defaultManager]requestImageDataAndOrientationForAsset:asset options:originOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, CGImagePropertyOrientation orientation, NSDictionary * _Nullable info) {
// 从info中获取是否云存储值 dispatch_async(dispatch_get_main_queue(), ^{
complet ? complet([info[PHImageResultIsInCloudKey] intValue] && !imageData) : nil;
});
}];
} else {
// 13之前 [[PHImageManager defaultManager]requestImageDataForAsset:asset options:originOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
// 从info中获取对应信息 dispatch_async(dispatch_get_main_queue(), ^{
complet ? complet([info[PHImageResultIsInCloudKey] intValue] && !imageData) : nil;
});
}];
}
}
}