码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-使用ALAssetsLibrary获取相册图片视频

时间:2017-10-22 17:15:35      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:set   bsp   script   color   integer   fail   bool   生产   error   

直接上代码:

 

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                           usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                               
                               // Filter down to only photos
                               [group setAssetsFilter:[ALAssetsFilter allPhotos]];
                               
                               // Grab the first photo return
                               [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
                                                       options:0
                                                    usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                                                        
                                                        if (result) {
                                                            
                                                            id repressentation = [result defaultRepresentation];
                                                            
                                                            // 可以生产一个AVAsset
                                                            NSURL *url = [repressentation url];
                                                            AVAsset *asset = [AVAsset assetWithURL:url];
                                                            
                                                            // 也可以直接获取image
                                                            self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithCGImage:[repressentation fullResolutionImage]]];
                                                            
                                                        }
                                                    }];
                           } failureBlock:^(NSError *error) {
                               
                               NSLog(@"Error: %@", [error localizedDescription]);
                           }];

 

iOS-使用ALAssetsLibrary获取相册图片视频

标签:set   bsp   script   color   integer   fail   bool   生产   error   

原文地址:http://www.cnblogs.com/zhouxihi/p/7709812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!