jrswizzle icon indicating copy to clipboard operation
jrswizzle copied to clipboard

- jr_swizzleMethod:withMethod:error: does not work on iOS7 sometimes

Open iwill opened this issue 11 years ago • 7 comments

- jr_swizzleMethod:withMethod:error: seems does not work on iOS7 sometimes;

// this works
    [self jr_swizzleMethod:@selector(show)
            withMethod:@selector(swizzledShow)
                 error:nil];

// but this does not, and I checked there is no any error
[self jr_swizzleMethod:@selector(dismissWithClickedButtonIndex:animated:)
            withMethod:@selector(swizzledDismissWithClickedButtonIndex:animated:)
                 error:nil];

iwill avatar Jun 20 '13 10:06 iwill

You may experiment a method caching issue : the ObjC runtime aggressively caches implementations for selectors. My experience on the topic is not profound, I have just noticed that sometimes the runtime behaves just as if the IMP cache would prevent swizzling to work. Maybe iOS7 caches even more aggressively.

As a consequence, I generally swizzle as soon as I can, before any instance of swizzled classes have been allocated.

groue avatar Jun 20 '13 10:06 groue

But I swizzled in the +load method of a UIAlertView category, it is early enough. I also do this for UIActionSheet, it works well.

iwill avatar Jun 20 '13 10:06 iwill

My hypothesis looks wrong, then. It could have been your solution, though :-)

I'm sorry, I don't know much more. I guess @rentzsch is much more aware than I am of the swizzling subtleties.

groue avatar Jun 20 '13 12:06 groue

Thank you :)

iwill avatar Jun 20 '13 15:06 iwill

BTW, you may check the result of jr_swizzleMethod:withMethod:error:, and the error.

groue avatar Jun 20 '13 18:06 groue

Yes, I checked, but no error!

iwill avatar Jun 21 '13 01:06 iwill

I came across this from a google search as I am having a problem with -dismissWithClickedButtonIndex:animated: on iOS 7. You may find that the problem is not with the swizzling but with the fact that -dismissWithClickedButtonIndex:animated: just doesn't work.

tdoidge avatar Sep 25 '13 09:09 tdoidge