-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIGPhotoAssetManager.m
More file actions
executable file
·61 lines (39 loc) · 1.28 KB
/
IGPhotoAssetManager.m
File metadata and controls
executable file
·61 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// IGPhotoAssetManager.m
// 照片选择和拍照Demo
//
// Created by ideago on 15/10/31.
// Copyright © 2015年 ideago. All rights reserved.
//
#import "IGPhotoAssetManager.h"
#import <Photos/Photos.h>
#import "IGPhotoModel.h"
@interface IGPhotoAssetManager()
@end
@implementation IGPhotoAssetManager
+ (instancetype)sharedManager
{
static dispatch_once_t onceToken;
static IGPhotoAssetManager *sharedManager;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc]init];
sharedManager.selectedPhotos = [NSMutableOrderedSet orderedSet];
});
return sharedManager;
}
- (NSMutableArray *)photos
{
if (_photos == nil || _photos.count == 0) {
_photos = [NSMutableArray array];
PHFetchOptions *options = [[PHFetchOptions alloc]init];
// 按创建时间降序排列
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:options];
for (PHAsset *asset in result) {
IGPhotoModel *model = [IGPhotoModel modelWithAsset:asset];
[_photos addObject:model];
}
}
return _photos;
}
@end