2

I've been working with the Apple sample code for viewing documents from here:

https://developer.apple.com/library/ios/samplecode/DocInteraction/Listings/ReadMe_txt.html

I have removed all the bits I don't need and got it working pretty much how I would like it to. The problem is I don't want users to have access to the "Actions" menu on the top right of the Document Controller. This appears every time you select a document from the list:

DocumentViewer Problem button

Ideally I would like to remove the button all together, though if I could disable it or disable all the options inside it that would also suffice. I found this question:

Open in + UIDocumentInteractionController : how to filter options in SDK iOS 6 (canPerformActions is deprecated)

But I couldn't figure out how to use the suggestion to disable the options inside the menu. I have uploaded the modified sample code here:

http://plasma.servebeer.com/DocSampleCode.zip

One final note is this will not be going on the App Store it is for private, personal use, so if there is an unofficial way then I would be interested in knowing that too.

Any help would be greatly appreciated, thanks in advance.

Plasma

Community
  • 1
  • 1
Plasma
  • 2,622
  • 2
  • 20
  • 35

3 Answers3

3

Use UINavigationControllerDelegate

@interface DITableViewController () <UIDocumentInteractionControllerDelegate, UINavigationControllerDelegate>

Assign navigationController delegate to self

- (void)viewDidLoad {

    [super viewDidLoad];
    self.navigationController.delegate = self;
}

Change documentInteractionControllerViewControllerForPreview

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)interactionController {

    return self.navigationController;
}

Add this UINavigationControllerDelegate method

// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

    if ([viewController isKindOfClass:[QLPreviewController class]]) {
        viewController.navigationItem.rightBarButtonItem = nil;
    }
}

Update for MP4 files

In MP4 files the action button is on the UIToolbar

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([viewController isKindOfClass:[QLPreviewController class]]) {
        viewController.navigationItem.rightBarButtonItem.customView = [[UIView alloc] init];
        UIBarButtonItem *item = viewController.toolbarItems.firstObject;
        item.customView = [[UIView alloc] init];
    }
}

N.B. This might not work in future versions of iOS

Warif Akhand Rishi
  • 23,920
  • 8
  • 80
  • 107
  • 1
    Amazing, thank you so much for the clear and concise answer. I had tried the rightBarButtonItem = nil; but was missing how to trigger it on the DocumentPreview pane. Working a treat now. :) – Plasma Feb 04 '16 at 13:47
  • May have been a little premature with the celebrations, it seems it removes it for every type of document apart from MP4 files. On a video preview it still shows the Action button. I checked and its of the same class as the others and the code gets executed but the button is still visible. :( Any ideas? – Plasma Feb 05 '16 at 22:51
  • A little more info on the iPad the Action button is still on the Navigation Bar, on the iPhone the navigation button is in the bottom left corner on a toolbar. If you could help me get rid of these too that would be great. – Plasma Feb 05 '16 at 23:13
  • I can confirm that this has removed it from the toolbar on the iPhone, however the last remaining issue is the one on the iPad. This is still visible on MP4 files. The main Navigation Controller has the Play button and the Action button in the top right. The app I'm working on will mainly be used on iPads so if you were able to help me resolve this that would be great. Thanks again for your time on this. – Plasma Feb 07 '16 at 14:48
  • Edited. Plz check again – Warif Akhand Rishi Feb 08 '16 at 05:06
  • Fantastic, thank you so much for sticking with me on this. That looks to have done the trick in the simulator, I will test it on a real device later. I will also see if I can work out how to send you some more reputation points! :) – Plasma Feb 08 '16 at 10:28
  • 1
    In my case iOS 10.0, It did not work. I just use webView. It works like a Magic. My code: NSURLRequest *request = [NSURLRequest requestWithURL:self.URLLoadOnWebView]; [self.webView loadRequest:request]; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; – Ravi Apr 04 '19 at 05:44
0

After creating QLPreviewController class you would need to set rightBarButtonItem to nil. Code snippet:

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.navigationItem.rightBarButtonItem = nil;

I did download project and after execution "Action" button was shown not in the top navigation item, but in the toolbar. Then in this case you would need to subclass QLPreviewController and override viewWillAppear as shown below.

@implementation ExViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSMutableArray *a = [NSMutableArray arrayWithArray:@[]];
    for (NSUInteger i = 0; i < self.toolbarItems.count; i++) {
        if (i == 0) {
            continue;
        }
        [a addObject:self.toolbarItems[i]];
    }
}

@end
Ramis
  • 13,985
  • 7
  • 81
  • 100
  • I suspect you downloaded the apple sample code and not my modified one which doesn't use the QLPreview controller. But thank you for the answer anyway as it might help others who are using the QL controller. – Plasma Feb 04 '16 at 13:49
-1

If you want to hide button the give answers will not work for iOS 10.0 and above in Swift language. You can use WKWebView. Hope it will save your time.

Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58