Skip to content

Instantly share code, notes, and snippets.

@steipete
Created March 26, 2012 11:00
Show Gist options
  • Save steipete/2204444 to your computer and use it in GitHub Desktop.
Save steipete/2204444 to your computer and use it in GitHub Desktop.
// Do I miss something obvious or is this the best way to detect if UIDocumentInteractionController is still open or not?
// (BOOL _isShowingOpenInMenu is in the class)
- (void)openInAction:(id)sender {
// do we need to dismiss a popover?
if ([self checkAndDismissPopoverForViewControllerClass:[UIDocumentInteractionController class] animated:YES]) {
return;
}
if (self.document.fileUrl) {
_isShowingOpenInMenu = NO;
documentInteractionController_ = [UIDocumentInteractionController interactionControllerWithURL:self.document.fileUrl];
documentInteractionController_.delegate = self;
if (PSIsIpad()) {
[documentInteractionController_ presentOptionsMenuFromBarButtonItem:sender animated:YES];
}else {
[documentInteractionController_ presentPreviewAnimated:YES];
}
}
}
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
documentInteractionController_.delegate = nil;
documentInteractionController_ = nil;
_isShowingOpenInMenu = NO;
}
- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {
_isShowingOpenInMenu = YES;
}
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller {
dispatch_async(dispatch_get_main_queue(), ^{
if (!_isShowingOpenInMenu) {
documentInteractionController_.delegate = nil;
documentInteractionController_ = nil;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment