jrswizzle
jrswizzle copied to clipboard
- jr_swizzleMethod:withMethod:error: does not work on iOS7 sometimes
- 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];
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.
But I swizzled in the +load method of a UIAlertView category, it is early enough. I also do this for UIActionSheet, it works well.
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.
Thank you :)
BTW, you may check the result of jr_swizzleMethod:withMethod:error:
, and the error.
Yes, I checked, but no error!
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.