//
//  UIImagePickerController+YMBlocks.m
//  PCDBank
//
//  Created by Gusont on 2020/12/15.
//  Copyright © 2020 YMBank. All rights reserved.
//

#import "UIImagePickerController+YMBlocks.h"

@interface UIImagePickerController()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@end
@implementation UIImagePickerController (YMBlocks)

- (UIImagePickerControllerBlcok)cancelBlock
{
    return objc_getAssociatedObject(self, @selector(cancelBlock));
}

- (void)setCancelBlock:(UIImagePickerControllerBlcok)cancelBlock
{
    self.delegate = self;
    objc_setAssociatedObject(self, @selector(cancelBlock), cancelBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (UIImagePickerControllerCompletionBlock)completionBlock
{
    return objc_getAssociatedObject(self, @selector(completionBlock));
}

- (void)setCompletionBlock:(UIImagePickerControllerCompletionBlock)completionBlock
{
    self.delegate = self;
    objc_setAssociatedObject(self, @selector(completionBlock), completionBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info
{
    if (self.completionBlock) {
        self.completionBlock(picker, info);
    }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    if (self.cancelBlock) {
        self.cancelBlock(picker);
    }
}

@end
