-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHow to use it
88 lines (64 loc) · 2.65 KB
/
How to use it
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
DemoCode below:
#import "DemoViewController.h"
#import "GFPhotos.h"
@interface DemoViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic,strong) GFPhotos* photo;
@end
@implementation DemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.创建Photos实例
GFPhotos* photo = [[GFPhotos alloc]init];
self.photo = photo;
}
- (IBAction)saveImageOnlyToSystemCollection:(id)sender {
[self saveImageOnlyToSystemCollectionWithImage:self.imageView.image];
}
- (IBAction)saveImageBothToCustomCollection:(id)sender {
[self saveImageBothToCustomCollectionWithImage:self.imageView.image Title:@"新相册"];
}
- (IBAction)getAllPhotos:(id)sender {
//2.获取所有图片或视频
[self.photo getAllImagesOrVideosWithMediaType:PHAssetMediaTypeImage];
//3.获取resultBlock
[self.photo getResultWithResultBlock:^(NSArray *allPhotos, NSArray *allVideos) {
NSLog(@"allphotos:%@",allPhotos);
}];
}
- (IBAction)deleteLastPhotoInCollection:(id)sender {
[self deleteLastPhotoInCollectionWithTitle:@"新相册"];
}
- (IBAction)getAllVideos:(id)sender {
[self.photo getAllImagesOrVideosWithMediaType:PHAssetMediaTypeVideo];
[self.photo getResultWithResultBlock:^(NSArray *allPhotos, NSArray *allVideos) {
NSLog(@"allVideo:%@",allVideos);
}];
}
#pragma mark-------- 只在系统相册创建添加照片
- (void)saveImageOnlyToSystemCollectionWithImage:(UIImage*)image{
[self.photo getRequestAuthorizationWithHandleBlock:^(PHAuthorizationStatus status) {
if (status != PHAuthorizationStatusAuthorized) {
return ;
}
[self.photo createdAssetsWithCreatedAssetId:[self.photo createdAssetIdWithImage:image]];
}];
}
#pragma mark---------在系统相册和自定义相册里都添加照片
- (void)saveImageBothToCustomCollectionWithImage:(UIImage*)image Title:(NSString* )title{
[self.photo getRequestAuthorizationWithHandleBlock:^(PHAuthorizationStatus status) {
if (status != PHAuthorizationStatusAuthorized) {
return ;
}
[self.photo saveImageIntoAlbumWithImage:image CreatedCollectionTitle:title];
}];
}
#pragma mark-------删除某自定义相册的最后一张图片
- (void)deleteLastPhotoInCollectionWithTitle:(NSString* )title{
[self.photo getRequestAuthorizationWithHandleBlock:^(PHAuthorizationStatus status) {
if (status != PHAuthorizationStatusAuthorized) {
return ;
}
[self.photo deletePhotoFormCollection:[self.photo createdCollectionWithTilte:title]];
}];
}