Skip to content

Instantly share code, notes, and snippets.

@Lascorbe
Forked from steipete/gist:7597165
Created November 22, 2013 09:25
Show Gist options
  • Save Lascorbe/7597214 to your computer and use it in GitHub Desktop.
Save Lascorbe/7597214 to your computer and use it in GitHub Desktop.
// 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