2
votes

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

3

3 Answers

3
votes

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

0
votes

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
-1
votes

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.