Created
April 28, 2015 23:10
-
-
Save joshhudnall/7ed771cbd6aed8438d6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIAlertViewCrashFix.h | |
// | |
// Created by Josh Hudnall on 4/28/15. | |
// | |
// | |
#import <Foundation/Foundation.h> | |
@interface UIAlertController (CrashFix) | |
@end | |
@interface UIViewController (CrashFix) | |
@end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIAlertViewCrashFix.m | |
// | |
// Created by Josh Hudnall on 4/28/15. | |
// | |
// | |
#import <objc/runtime.h> | |
#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(emf_shouldAutorotate)); | |
method_exchangeImplementations(original, swizzle); | |
// Swizzle | |
original = class_getInstanceMethod(class, @selector(supportedInterfaceOrientations)); | |
swizzle = class_getInstanceMethod(class, @selector(emf_supportedInterfaceOrientations)); | |
method_exchangeImplementations(original, swizzle); | |
// Swizzle | |
original = class_getInstanceMethod(class, @selector(preferredInterfaceOrientationForPresentation)); | |
swizzle = class_getInstanceMethod(class, @selector(emf_preferredInterfaceOrientationForPresentation)); | |
method_exchangeImplementations(original, swizzle); | |
}); | |
} | |
- (BOOL)emf_shouldAutorotate { | |
return IS_IPAD; | |
} | |
- (NSUInteger)emf_supportedInterfaceOrientations { | |
return (IS_IPAD) ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationPortrait; | |
} | |
- (UIInterfaceOrientation)emf_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(emf_shouldAutorotate)); | |
method_exchangeImplementations(original, swizzle); | |
// Swizzle | |
original = class_getInstanceMethod(class, @selector(supportedInterfaceOrientations)); | |
swizzle = class_getInstanceMethod(class, @selector(emf_supportedInterfaceOrientations)); | |
method_exchangeImplementations(original, swizzle); | |
// Swizzle | |
original = class_getInstanceMethod(class, @selector(preferredInterfaceOrientationForPresentation)); | |
swizzle = class_getInstanceMethod(class, @selector(emf_preferredInterfaceOrientationForPresentation)); | |
method_exchangeImplementations(original, swizzle); | |
}); | |
} | |
- (BOOL)emf_shouldAutorotate { | |
return IS_IPAD; | |
} | |
- (NSUInteger)emf_supportedInterfaceOrientations { | |
return (IS_IPAD) ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationPortrait; | |
} | |
- (UIInterfaceOrientation)emf_preferredInterfaceOrientationForPresentation { | |
UIDevice* device = [UIDevice currentDevice]; | |
if (device.orientation == UIInterfaceOrientationPortraitUpsideDown) { | |
return UIInterfaceOrientationPortraitUpsideDown; | |
} | |
return UIInterfaceOrientationPortrait; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment