Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

added blocks for UIImagePickerController #174

Closed
wants to merge 2 commits into from
Closed

Conversation

jksk
Copy link

@jksk jksk commented Sep 5, 2013

BlocksKit support for UIImagePickerController.

@segiddins
Copy link
Contributor

@jksk could you add some unit tests?

@jksk
Copy link
Author

jksk commented Sep 8, 2013

@segiddins Added unit tests.

didCancel = YES;
};

[_subject.dynamicDelegate imagePickerControllerDidCancel:_subject];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be called on _subject.delegate

@jksk
Copy link
Author

jksk commented Sep 8, 2013

Gotcha. I haven't looked through it that carefully, so there might be a good reason why the UIImagePickerController is different from the rest of the UIKit blocks. But just FYI, that's not the pattern that the other UIKit tests follow. The UIActionSheet, UIAlertView and UIWebView tests all call the dynamicDelegate, not the delegate.

@tonyxiao
Copy link

tonyxiao commented Oct 2, 2013

Does this actually work? For some reason (at least in iOS 7), seems that the method swizzling bit is never called because the initial class_addMethod call seems to succeed.

    const char *getterTypes = "@@:";
    const char *setterTypes = "v@:@";

    if (!class_addMethod(self, getter, getterImplementation, getterTypes)) {
        class_addMethod(self, a2_getter, getterImplementation, getterTypes);
        Method method = class_getInstanceMethod(self, getter);
        Method a2_method = class_getInstanceMethod(self, a2_getter);
        method_exchangeImplementations(method, a2_method);
    }

    if (!class_addMethod(self, setter, setterImplementation, setterTypes)) {
        class_addMethod(self, a2_setter, setterImplementation, setterTypes);
        Method method = class_getInstanceMethod(self, setter);
        Method a2_method = class_getInstanceMethod(self, a2_setter);
        method_exchangeImplementations(method, a2_method);
    }

    propertyMap[protocolName] = delegateName;

Therefore when using blocks, delegate is not being correctly set.

@a2
Copy link
Collaborator

a2 commented Oct 2, 2013

UIImagePickerController uses the delegate property instead of the _delegate ivar when accessing its delegate. That's why the swizzling bit is never called.

@tonyxiao
Copy link

tonyxiao commented Oct 2, 2013

So how do we workaround that? As it stands the block properties doesn't
work due to swizzling bit not being called.

@a2
Copy link
Collaborator

a2 commented Oct 2, 2013

This is one of the problem with Apple's internal inconsistencies. I suggest using an A2DynamicDelegate and implementing the methods manually.

@tonyxiao
Copy link

tonyxiao commented Oct 2, 2013

Why not swizzle the method without using class_addMethod first? Problem with class_addMethod is that it overrides implementation in super class causing the breakage.

@zwaldowski
Copy link
Collaborator

That's not a practice we can apply generally. Lots of private Apple subclasses of UIKit things do that (i.e., "self.delegate = self;" and doing so in BlocksKit heavily broke them.

@pronebird
Copy link

Any progress since then? I need it badly. :/

@zwaldowski zwaldowski closed this Mar 11, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants