// // UIAlertViewCrashFix.m // // Created by Josh Hudnall on 4/28/15. // // #import #import "UIAlertView+CrashFix.h" @implementation UIAlertController (CrashFix) + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; Method original, swizzle; // Swizzle original = class_getInstanceMethod(class, @selector(shouldAutorotate)); swizzle = class_getInstanceMethod(class, @selector(jh_shouldAutorotate)); method_exchangeImplementations(original, swizzle); // Swizzle original = class_getInstanceMethod(class, @selector(supportedInterfaceOrientations)); swizzle = class_getInstanceMethod(class, @selector(jh_supportedInterfaceOrientations)); method_exchangeImplementations(original, swizzle); // Swizzle original = class_getInstanceMethod(class, @selector(preferredInterfaceOrientationForPresentation)); swizzle = class_getInstanceMethod(class, @selector(jh_preferredInterfaceOrientationForPresentation)); method_exchangeImplementations(original, swizzle); }); } - (BOOL)jh_shouldAutorotate { return IS_IPAD; } - (NSUInteger)jh_supportedInterfaceOrientations { return (IS_IPAD) ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationPortrait; } - (UIInterfaceOrientation)jh_preferredInterfaceOrientationForPresentation { UIDevice* device = [UIDevice currentDevice]; if (device.orientation == UIInterfaceOrientationPortraitUpsideDown) { return UIInterfaceOrientationPortraitUpsideDown; } return UIInterfaceOrientationPortrait; } @end @implementation UIViewController (CrashFix) + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; Method original, swizzle; // Swizzle original = class_getInstanceMethod(class, @selector(shouldAutorotate)); swizzle = class_getInstanceMethod(class, @selector(jh_shouldAutorotate)); method_exchangeImplementations(original, swizzle); // Swizzle original = class_getInstanceMethod(class, @selector(supportedInterfaceOrientations)); swizzle = class_getInstanceMethod(class, @selector(jh_supportedInterfaceOrientations)); method_exchangeImplementations(original, swizzle); // Swizzle original = class_getInstanceMethod(class, @selector(preferredInterfaceOrientationForPresentation)); swizzle = class_getInstanceMethod(class, @selector(jh_preferredInterfaceOrientationForPresentation)); method_exchangeImplementations(original, swizzle); }); } - (BOOL)jh_shouldAutorotate { return IS_IPAD; } - (NSUInteger)jh_supportedInterfaceOrientations { return (IS_IPAD) ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationPortrait; } - (UIInterfaceOrientation)jh_preferredInterfaceOrientationForPresentation { UIDevice* device = [UIDevice currentDevice]; if (device.orientation == UIInterfaceOrientationPortraitUpsideDown) { return UIInterfaceOrientationPortraitUpsideDown; } return UIInterfaceOrientationPortrait; } @end