Skip to content

Get image from asset #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion BFRImageViewController/BFRImageContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "BFRImageContainerViewController.h"

#import <Photos/Photos.h>
#import <DACircularProgress/DACircularProgressView.h>
#import "AFNetworking.h"

Expand Down Expand Up @@ -41,9 +42,11 @@ - (void)viewDidLoad {
self.progressView = [self createProgressView];
[self.view addSubview:self.progressView];
[self retrieveImageFromURL];
} else {
} else if ([self.imgSrc isKindOfClass:[UIImage class]]) {
self.imgLoaded = (UIImage *)self.imgSrc;
[self addImageToScrollView];
} else if ([self.imgSrc isKindOfClass:[PHAsset class]]){
[self retrieveImageFromAsset];
}

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

- (void)retrieveImageFromAsset {
if (![self.imgSrc isKindOfClass:[PHAsset class]]) {
return;
}

PHImageRequestOptions *reqOptions = [PHImageRequestOptions new];
reqOptions.synchronous = YES;
[[PHImageManager defaultManager] requestImageDataForAsset:self.imgSrc options:reqOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
self.imgLoaded = [UIImage imageWithData:imageData];
[self addImageToScrollView];
}];
}
- (void)retrieveImageFromURL {
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:(NSURL *)self.imgSrc cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:0];

Expand Down