The question is simple. I need the same thing as usual - how to replace the original method with mine, but @selector(presentViewController:animated:completion:)on iOS9? It works only in the iOS9 simulator, and not in a real device.
Yes, this code is called, but then you get EXC_BAD_ACCESS.
To test it, I created a test application from the Master Parts template, added a button and added the following code:
UIViewController *vc = [[UIViewController alloc] init];
[self.navigationController presentViewController:vc animated:YES completion:nil];
UPDATED
@implementation UINavigationController (Extension)
- (void)swizzledPresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
[ self swizzledPresentViewController:viewControllerToPresent animated:flag completion:completion ];
}
#pragma mark -
+ (void)swizzle:(Class)class oldSelector:(SEL)old newSelector:(SEL)new
{
Method oldMethod = class_getInstanceMethod(class, old);
Method newMethod = class_getInstanceMethod(class, new);
if(class_addMethod(class, old, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
{
class_replaceMethod(class, new, method_getImplementation(oldMethod), method_getTypeEncoding(oldMethod));
}
else
{
method_exchangeImplementations(oldMethod, newMethod);
}
}
+ (void)load
{
[self swizzle:UINavigationController.class oldSelector:@selector(presentViewController:animated:completion:) newSelector:@selector(swizzledPresentViewController:animated:completion:)];
}
@end
And almost the same code is written on the NSHipster website
UPDATED
A WARNING! This error is reproduced on very random devices (in my case it is iphone5 + ios9.0, but other users have newer devices with iOS9.1 as well).