iOS---如何获取手机的本地照片和相册
2017-03-03 13:39
387 查看
__weak ViewController *weakSelf = self; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { if (group != nil) { [weakSelf.groupArrays addObject:group]; } else { [weakSelf.groupArrays enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [obj enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if ([result thumbnail] != nil) { // 照片 if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]){ // NSDate *date= [result valueForProperty:ALAssetPropertyDate]; // UIImage *image = [UIImage imageWithCGImage:[result thumbnail]]; // NSString *fileName = [[result defaultRepresentation] filename]; // NSURL *url = [[result defaultRepresentation] url]; // int64_t fileSize = [[result defaultRepresentation] size]; // // NSLog(@"date = %@",date); // NSLog(@"fileName = %@",fileName); // NSLog(@"url = %@",url); // NSLog(@"fileSize = %lld",fileSize); // // // UI的更新记得放在主线程,要不然等子线程排队过来都不知道什么年代了,会很慢的 // dispatch_async(dispatch_get_main_queue(), ^{ // self.litimgView.image = image; // }); NSLog(@"读取到照片了"); } // 视频 else if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo] ){ NSURL *url = [[result defaultRepresentation] url]; UIImage *image = [UIImage imageWithCGImage:[result thumbnail]]; NSLog(@"%@",url); dispatch_async(dispatch_get_main_queue(), ^{ self.litimgView.image = image; }); // 和图片方法类似 } } }]; }]; } }; ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) { NSString *errorMessage = nil; switch ([error code]) { case ALAssetsLibraryAccessUserDeniedError: case ALAssetsLibraryAccessGloballyDeniedError: errorMessage = @"用户拒绝访问相册,请在<隐私>中开启"; break; default: errorMessage = @"Reason unknown."; break; } dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"错误,无法访问!" message:errorMessage delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alertView show]; }); }; ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:listGroupBlock failureBlock:failureBlock]; });
相关文章推荐
- iOS---如何获取手机的本地照片和相册
- 如何从手机相册或相机获取照片
- iOS 如何正确的从iPhone相册中导出和保存照片?
- 获取IOS系统相册中的照片
- iOS如何获取手机当前的网络状态
- iOS 上传照片到服务器 获取相册和拍照功能的照片 照片压缩上传
- IOS拍照---》保存到相册----》并且获取照片的ALasset传到相册
- ios 上传头像 从本地获取照片、拍照及剪裁并上传到界面上
- iOS 根据图片URL从本地相册获取图片
- IOS中如何获取手机的当前IP
- iOS开发 - 如何获取设备的总容量和可用容量 网络运营商 3g/wifi判断 手机型号
- iOS开发——打开手机相册,获取图片
- ios如何获取手机的网络状态和运营商名称
- ios如何获取手机的网络状态和运营商名称
- IOS SWIFT alte形式获取手机的相册和相机
- ImageView 实现从手机相册中获取照片,并可以进行裁剪或者适屏展示
- iOS如何获取手机当前的网络状态
- iOS开发--删除本地相册照片
- 【学习ios之路:UI系列】获取通过UIImagePackerController获取的系统相册图片的名称信息及保存系统相册到本地
- iOS开发swift如何调用系统相册和相机获取图片设置用户头像