Easier to use PhotosKit
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Xcode 6
- iOS 8.0 +
LIPhotosKitManager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "LIPhotosKitManager"
#import <LIPhotosKitManager.h> //---------------------------------------1
@interface ViewController ()<LIPhotosKitManagerDelegate>
@property (nonatomic, strong) LIPhotosKitManager *manager; //-----------2
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//------------------------------------------------------------------3
self.manager = [[LIPhotosKitManager alloc] init];
self.manager.delagate = self;
}
- (void)managerDidReceivePhotoLibraryChangeNotification
{
// delegate method
// update your datasource and refresh ui
}
@end
You can use allSystemAlbums
or allUserCustomAlbums
methods to get albums in your device. These methods return a array contain LIAlbum
objects.
NSArray *systemAlbums = [self.manager allSystemAlbums];
NSArray *customAlbums = [self.manager allUserCustomAlbums];
Before obtaining Photos, you must get the LIID
object. There are two ways to get that object. One is read from LIAlbum
object, another is use the allPhotosIDSortByCreateDateAscending:
NSArray *imageIDs = [self.manager allPhotosIDSortByCreateDateAscending:YES];
Everything is ready ,use the following methods to get the photos you want:
- requestThumbnailImageForID:size:contentMode:target:resultHandler:
- requestOriginalImageForID:target:resultHandler:
- requestOriginalImageDataForID:target:resultHandler:
Esample
LIID *idObj = self.imageIDs[index];
UIImageView *imageView = self.imageView;
[self.manager requestThumbnailImageForID:idObj size:CGSizeMake(100, 100) contentMode:0 target:imageView resultHandler:^(UIImage *result, id target, NSDictionary *info) {
UIImageView *imageView = target;
imageView.image = result;
}];
Ruwei Li, liruwei0109@outlook.com
LIPhotosKitManager is available under the MIT license. See the LICENSE file for more info.