Created
November 22, 2013 09:21
-
-
Save steipete/7597165 to your computer and use it in GitHub Desktop.
Get the UIPopoverController out of "managed" popovers.
This file contains hidden or 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
// HACK, but not critical if it fails. | |
+ (UIPopoverController *)popoverControllerForObject:(id)object { | |
if (!PSIsIpad()) return nil; | |
UIPopoverController *popoverController = object; | |
#ifndef PSPDFKIT_DONT_USE_OBFUSCATED_PRIVATE_API | |
NSString *printInteractionControllerKeyPath = [NSString stringWithFormat:@"%1$@%2$@.%1$@%3$@%4$@%5$@.%6$@%5$@", @"print", @"State", @"Panel", @"View", @"Controller", @"pover"]; | |
@try { | |
if ([object isKindOfClass:UIPopoverController.class]) { | |
popoverController = object; | |
}else if ([object isKindOfClass:UIPrintInteractionController.class]) { | |
popoverController = [object valueForKeyPath:printInteractionControllerKeyPath]; | |
}else { | |
// Works at least for UIDocumentInteractionController and UIActionSheet | |
popoverController = [object valueForKey:PROPERTY(popoverController)]; | |
} | |
} | |
@catch (NSException *exception) { | |
@try { | |
// If Apple fixes the typo in UIPrintPanelViewController and renames the _poverController ivar into _popoverController | |
printInteractionControllerKeyPath = [printInteractionControllerKeyPath stringByReplacingOccurrencesOfString:@"pover" withString:@"popover"]; | |
popoverController = [object valueForKeyPath:printInteractionControllerKeyPath]; | |
} | |
@catch (NSException *exception) { | |
popoverController = nil; | |
} | |
} | |
#endif | |
if ([popoverController isKindOfClass:UIPopoverController.class]) return popoverController; | |
else return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment