直播app开发搭建,ios 获取手机中所有图片
首先我们得导入相关的库
#import <AssetsLibrary/AssetsLibrary.h>
代码:
photo = [[NSMutableArray alloc]init];
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(dispatchQueue, ^(void){
//遍历所有相册
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop){
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
NSString *assetType = [result valueForProperty:ALAssetPropertyType];
NSDictionary *url = [result valueForProperty:ALAssetPropertyURLs];
if ([assetType isEqualToString:ALAssetTypePhoto])
{
[photo addObject:url];
NSLog(@"url == %@", url);
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
if (photo != nil)
{
//我不知道这里来调用会不会有什么不好
}
});
}
failureBlock:^(NSError *error)
{
NSLog(@"failed");
}];
});
这样我们所有的图片的url 就放到 photo 这个数组中了,调用的话:
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init] ;
[lib assetForURL:[[photo objectAtIndex:0] valueForKey:@"public.jpeg"] resultBlock:^(ALAsset *asset)
{
//这里可以获取照片的相关信息
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
//获取缩略图
CGImageRef imgRef = asset.thumbnail;
imgView.image = [UIImage imageWithCGImage:imgRef
scale:assetRep.scale
orientation:(UIImageOrientation)assetRep.orientation];
}
failureBlock:^(NSError *error)
{
NSLog(@"failed!!");
}];
以上就是 直播app开发搭建,ios 获取手机中所有图片,更多内容欢迎关注之后的文章
标签:url,photo,app,ios,dispatch,直播,ALAssetsLibrary From: https://www.cnblogs.com/yunbaomengnan/p/17061404.html