Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iwill opened this issue Jun 20, 2013 · 7 comments
Open

Comments

@iwill
Copy link

iwill commented Jun 20, 2013

- 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];
@groue
Copy link

groue commented Jun 20, 2013

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.

@iwill
Copy link
Author

iwill commented Jun 20, 2013

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

@groue
Copy link

groue commented Jun 20, 2013

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.

@iwill
Copy link
Author

iwill commented Jun 20, 2013

Thank you :)

@groue
Copy link

groue commented Jun 20, 2013

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

@iwill
Copy link
Author

iwill commented Jun 21, 2013

Yes, I checked, but no error!

@tdoidge
Copy link

tdoidge commented Sep 25, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants