Skip to content

Commit bd37da5

Browse files
author
Jordan Morgan
committed
Merge pull request #4 from bufferapp/task/support-PHAsset
Get image from asset
2 parents 82f1e9d + 823efff commit bd37da5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

BFRImageViewController/BFRImageContainerViewController.m

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "BFRImageContainerViewController.h"
1010

11+
#import <Photos/Photos.h>
1112
#import <DACircularProgress/DACircularProgressView.h>
1213
#import "AFNetworking.h"
1314

@@ -41,9 +42,11 @@ - (void)viewDidLoad {
4142
self.progressView = [self createProgressView];
4243
[self.view addSubview:self.progressView];
4344
[self retrieveImageFromURL];
44-
} else {
45+
} else if ([self.imgSrc isKindOfClass:[UIImage class]]) {
4546
self.imgLoaded = (UIImage *)self.imgSrc;
4647
[self addImageToScrollView];
48+
} else if ([self.imgSrc isKindOfClass:[PHAsset class]]){
49+
[self retrieveImageFromAsset];
4750
}
4851

4952
//Animator - used to snap the image back to the center when done dragging
@@ -278,6 +281,18 @@ - (void)dismissUI {
278281
[[NSNotificationCenter defaultCenter] postNotificationName:@"DismissUI" object:nil];
279282
}
280283

284+
- (void)retrieveImageFromAsset {
285+
if (![self.imgSrc isKindOfClass:[PHAsset class]]) {
286+
return;
287+
}
288+
289+
PHImageRequestOptions *reqOptions = [PHImageRequestOptions new];
290+
reqOptions.synchronous = YES;
291+
[[PHImageManager defaultManager] requestImageDataForAsset:self.imgSrc options:reqOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
292+
self.imgLoaded = [UIImage imageWithData:imageData];
293+
[self addImageToScrollView];
294+
}];
295+
}
281296
- (void)retrieveImageFromURL {
282297
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:(NSURL *)self.imgSrc cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:0];
283298

0 commit comments

Comments
 (0)