Skip to content
This repository was archived by the owner on Nov 29, 2022. It is now read-only.
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion Examples/PhotoPicker/PhotoPicker/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,24 @@ - (void)presentPhotoSearch:(id)sender
picker.supportedServices = DZNPhotoPickerControllerService500px | DZNPhotoPickerControllerServiceFlickr | DZNPhotoPickerControllerServiceGiphy;
picker.allowsEditing = NO;
picker.cropMode = DZNPhotoEditorViewControllerCropModeCircular;
// picker.cropMode = DZNPhotoEditorViewControllerCropModeNone;
picker.initialSearchTerm = @"Chile";
picker.enablePhotoDownload = YES;
picker.allowAutoCompletedSearch = YES;
picker.infiniteScrollingEnabled = YES;
picker.title = @"Search Photos";


[picker setSelectionBlock:^(DZNPhotoPickerController *picker, NSDictionary *info) {
NSLog(@"selected: %@",info);

if(picker.cropMode == DZNPhotoEditorViewControllerCropModeNone){
//DZNPhotoPickerController did early dismiss but processing still does proceeding
[picker popToViewController:self animated:YES];
}
}];

[picker setFinalizationBlock:^(DZNPhotoPickerController *picker, NSDictionary *info){
NSLog(@"finished: %@",info);
[self updateImageWithPayload:info];
[self dismissController:picker];
}];
Expand Down
27 changes: 21 additions & 6 deletions Source/Classes/Core/DZNPhotoDisplayViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,22 @@ - (void)loadView

_selectedService = DZNFirstPhotoServiceFromPhotoServices(self.navigationController.supportedServices);
NSAssert((_selectedService > 0), @"DZNPhotoPickerController requieres at least 1 supported photo service provider");

self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeAll;

NSAssert(!self.navigationController.initialSelectedService || self.navigationController.initialSelectedService & self.navigationController.supportedServices, @"Provided 'initialSelectedService' doesn't support in 'supportedServices'");
if(self.navigationController.initialSelectedService & self.navigationController.supportedServices){
NSArray * initialSelectedService = NSArrayFromServices(self.navigationController.initialSelectedService);
NSAssert(initialSelectedService.count==1,@"Only one service flag can be assigned to initialSelectedService.");
_segmentedControlTitles = [NSSet setWithArray:[initialSelectedService arrayByAddingObjectsFromArray:_segmentedControlTitles]].allObjects;
_selectedService = self.navigationController.initialSelectedService;
}

if(_segmentedControlTitles.count>1){
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeAll;
}else{
self.extendedLayoutIncludesOpaqueBars = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
}
self.automaticallyAdjustsScrollViewInsets = YES;
self.definesPresentationContext = YES;

Expand Down Expand Up @@ -418,8 +431,10 @@ - (void)resetPhotos
*/
- (void)selectedMetadata:(DZNPhotoMetadata *)metadata
{
[metadata postMetadataUpdate:nil notification:DZNPhotoPickerDidSelectNotification];

if (!self.navigationController.enablePhotoDownload) {
[metadata postMetadataUpdate:nil];
[metadata postMetadataUpdate:nil notification:DZNPhotoPickerDidFinishPickingNotification];
}
else if (self.navigationController.allowsEditing) {

Expand All @@ -432,7 +447,7 @@ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata
[self.navigationController pushViewController:controller animated:YES];

[controller setAcceptBlock:^(DZNPhotoEditorViewController *editor, NSDictionary *userInfo){
[metadata postMetadataUpdate:userInfo];
[metadata postMetadataUpdate:userInfo notification:DZNPhotoPickerDidFinishPickingNotification];
[self.navigationController popViewControllerAnimated:YES];
}];

Expand Down Expand Up @@ -472,7 +487,7 @@ - (void)selectedMetadata:(DZNPhotoMetadata *)metadata
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished){
if (image) {
NSDictionary *userInfo = @{UIImagePickerControllerOriginalImage: image};
[metadata postMetadataUpdate:userInfo];
[metadata postMetadataUpdate:userInfo notification:DZNPhotoPickerDidFinishPickingNotification];
}
else {
[self setLoadingError:error];
Expand Down
17 changes: 15 additions & 2 deletions Source/Classes/Core/DZNPhotoPickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
@interface DZNPhotoPickerController : UINavigationController

typedef void (^DZNPhotoPickerControllerSelectionBlock)(DZNPhotoPickerController *picker, NSDictionary *info);
typedef void (^DZNPhotoPickerControllerFinalizationBlock)(DZNPhotoPickerController *picker, NSDictionary *info);
typedef void (^DZNPhotoPickerControllerFailureBlock)(DZNPhotoPickerController *picker, NSError *error);
typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerController *picker);
Expand All @@ -29,6 +30,8 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll
@property (nonatomic, assign) id <UINavigationControllerDelegate, DZNPhotoPickerControllerDelegate> delegate;
/** The photo services to be supported by the controller. Default are 500px & Flickr. */
@property (nonatomic) DZNPhotoPickerControllerServices supportedServices;
/** A photo service that will initially be selected at first when controller presented. */
@property (nonatomic) DZNPhotoPickerControllerServices initialSelectedService;
/** YES if the user is allowed to edit a selected image. Default is NO. */
@property (nonatomic) BOOL allowsEditing;
/** An optional string term for auto-starting the photo search, as soon as the picker is presented. */
Expand All @@ -41,7 +44,9 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll
@property (nonatomic) DZNPhotoPickerControllerCCLicenses supportedLicenses;
/** YES if the picker should download the full size photo after selecting its thumbnail, when allowsEditing is NO. Default is YES. */
@property (nonatomic) BOOL enablePhotoDownload;
/** A block to be executed whenever the user pickes a new photo. Use this block to replace delegate method photoPickerController:didFinishPickingPhotoWithInfo: */
/** A block to be executed whenever the user selects a new photo in collection view(album view). Use this block to replace delegate method photoPickerController:didSelectPhotoWithInfo: */
@property (nonatomic, strong) DZNPhotoPickerControllerSelectionBlock selectionBlock;
/** A block to be executed whenever the user pickes a new photo, and internal processing was finished. Use this block to replace delegate method photoPickerController:didFinishPickingPhotoWithInfo: */
@property (nonatomic, strong) DZNPhotoPickerControllerFinalizationBlock finalizationBlock;
/** A block to be executed whenever an error occurs while picking a photo. Use this block to replace delegate method photoPickerController:didFailedPickingPhotoWithError: */
@property (nonatomic, strong) DZNPhotoPickerControllerFailureBlock failureBlock;
Expand Down Expand Up @@ -89,7 +94,15 @@ typedef void (^DZNPhotoPickerControllerCancellationBlock)(DZNPhotoPickerControll
@required

/**
Tells the delegate that the user picked a new photo.
Tells the delegate that the user selected a new photo in album view.

@param picker The controller object managing the photo search picker interface.
@param userInfo A dictionary containing the original image. The dictionary also contains some information of selected photo. For exiting keys @see DZNPhotoPickerControllerConstants.h.
*/
- (void)photoPickerController:(DZNPhotoPickerController *)picker didSelectPhotoWithInfo:(NSDictionary *)userInfo;

/**
Tells the delegate that the user picked a new photo and finalized its processing internally.

@param picker The controller object managing the photo search picker interface.
@param userInfo A dictionary containing the original image and the edited image. The dictionary also contains any relevant editing information (crop size, crop mode). For exiting keys @see DZNPhotoPickerControllerConstants.h.
Expand Down
15 changes: 15 additions & 0 deletions Source/Classes/Core/DZNPhotoPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "DZNPhotoMetadata.h"

#import <MobileCoreServices/UTCoreTypes.h>
#import <DZNPhotoPickerController/DZNPhotoPickerControllerConstants.h>

static DZNPhotoPickerControllerFinalizationBlock _finalizationBlock;
static DZNPhotoPickerControllerFailureBlock _failureBlock;
Expand Down Expand Up @@ -55,6 +56,7 @@ - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSelectPhoto:) name:DZNPhotoPickerDidSelectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPickingPhoto:) name:DZNPhotoPickerDidFinishPickingNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFailPickingPhoto:) name:DZNPhotoPickerDidFailPickingNotification object:nil];

Expand Down Expand Up @@ -134,6 +136,18 @@ - (void)showPhotoDisplayController
}

/* Called by a notification whenever the user picks a photo. */
- (void)didSelectPhoto:(NSNotification *)notification
{
if (self.selectionBlock) {
self.selectionBlock(self, notification.userInfo);

}
else if (self.delegate && [self.delegate respondsToSelector:@selector(photoPickerController:didSelectPhotoWithInfo:)]){
[self.delegate photoPickerController:self didSelectPhotoWithInfo:notification.userInfo];
}
}

/* Called by a notification whenever the user picks a photo and internal process was completed. */
- (void)didFinishPickingPhoto:(NSNotification *)notification
{
if (self.finalizationBlock) {
Expand Down Expand Up @@ -197,6 +211,7 @@ - (void)viewDidUnload
- (void)dealloc
{
_initialSearchTerm = nil;
_selectionBlock = nil;
_finalizationBlock = nil;
_cancellationBlock = nil;
}
Expand Down
1 change: 1 addition & 0 deletions Source/Classes/Core/DZNPhotoPickerControllerConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern NSString *const DZNPhotoPickerControllerCropMode; // An NSSt
extern NSString *const DZNPhotoPickerControllerCropZoomScale; // An NSString (from 1.0 to maximum zoom scale, 2.0f)
extern NSString *const DZNPhotoPickerControllerPhotoMetadata; // An NSDictionary containing metadata from a captured photo

extern NSString *const DZNPhotoPickerDidSelectNotification; // The notification key used when selecting a photo, and finalization will start.
extern NSString *const DZNPhotoPickerDidFinishPickingNotification; // The notification key used when picking a photo finished.
extern NSString *const DZNPhotoPickerDidFailPickingNotification; // The notification key used when picking a photo failed.

Expand Down
1 change: 1 addition & 0 deletions Source/Classes/Core/DZNPhotoPickerControllerConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
NSString *const DZNPhotoPickerControllerCropZoomScale = @"com.dzn.photoPicker.cropZoomScale";
NSString *const DZNPhotoPickerControllerPhotoMetadata = @"com.dzn.photoPicker.photoMetadata";

NSString *const DZNPhotoPickerDidSelectNotification = @"com.dzn.photoPicker.didSelectNotification";
NSString *const DZNPhotoPickerDidFinishPickingNotification = @"com.dzn.photoPicker.didFinishPickingNotification";
NSString *const DZNPhotoPickerDidFailPickingNotification = @"com.dzn.photoPicker.didFinishPickingWithErrorNotification";

Expand Down
2 changes: 1 addition & 1 deletion Source/Classes/Services/DZNPhotoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@
@param cropMode The crop mode being used.
@param photoDescription The photo metadata.
*/
- (void)postMetadataUpdate:(NSDictionary *)userInfo;
- (void)postMetadataUpdate:(NSDictionary *)userInfo notification:(NSString *)name;

@end
17 changes: 9 additions & 8 deletions Source/Classes/Services/DZNPhotoMetadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,22 @@ - (NSString *)description

#pragma mark - Notification

- (void)postMetadataUpdate:(NSDictionary *)userInfo
- (void)postMetadataUpdate:(NSDictionary *)userInfo notification:(NSString *)name
{
NSLog(@"postMetadataUpdate : %@", userInfo);
NSLog(@"postMetadataUpdate : %@, notification: %@", userInfo, name);

NSMutableDictionary *_userInfo = [[NSMutableDictionary alloc] initWithDictionary:userInfo];

NSDictionary *payload = [self payload];

if (payload.allKeys.count > 0) {
[_userInfo setObject:payload forKey:DZNPhotoPickerControllerPhotoMetadata];
_userInfo[DZNPhotoPickerControllerPhotoMetadata] = payload;
}
[[NSNotificationCenter defaultCenter] postNotificationName:DZNPhotoPickerDidFinishPickingNotification object:nil userInfo:_userInfo];

[[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:_userInfo];
}


- (NSDictionary *)payload
{
NSMutableDictionary *attributes = [NSMutableDictionary new];
Expand Down