1

Is it possible to manage the list of apps that UIDocumentInteractionController is going to present for opening my file in? Actually, I need to create black and white lists of apps. I took a look at UIDocumentInteractionControllerDelegate but it doesn't contain the needed methods..only
- (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application

and I need something like

-(BOOL)shouldPresentForOpenInApplication: (NSString *)

Stas
  • 9,925
  • 9
  • 42
  • 77
  • What do you mean by "create black and white lists"? And no, you can't filter the list of apps. It's based on the UTI of the document being shared. – rmaddy Sep 03 '14 at 15:51
  • This means that the user has an ability to block some apps from showing in Open in list. The order of suggested apps is managed by white list (apps from white list go first) something like that, hope you understand what I'm talking about. – Stas Sep 04 '14 at 08:33

1 Answers1

1

Actually I figured out how to do it. This is a bit like a trick but it works. All you need to do is to implement a delegate's method, like so

- (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application {
    BOOL isAppAllowed = YES;
    // Make a decision based on app bundle identifier whether to open it or not
    if (isAppAllowed) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self showRejectionMessage];
        });
        [self stopSendingFileUsingDocController:controller toApplication:application];
    }
}

And the actual method in which we deceive the doc controller by substituting bad url.

-(void)stopSendingFileUsingDocController:(UIDocumentInteractionController *)controller toApplication:(NSString *)application
{
    NSURL *documentURL = controller.URL;
    NSString *filePath = [documentURL path];
    filePath = [filePath stringByDeletingLastPathComponent];
    NSString *filename = [filePath lastPathComponent];
    NSMutableString *carets = [NSMutableString string];
    for (NSUInteger i = 0; i < [filename length]; i++)
    {
        [carets appendString:@"^"];
    }

#ifndef __clang_analyzer__
    filePath = [filePath stringByAppendingPathComponent:carets];
    NSURL *newURL = [[NSURL alloc] initFileURLWithPath:filePath];
    controller.URL = newURL;
#endif
    [self documentInteractionController:controller didEndSendingToApplication:application];
}
mylogon
  • 2,772
  • 2
  • 28
  • 42
Stas
  • 9,925
  • 9
  • 42
  • 77
  • This approach won't work always because `willBeginSendingToApplication` is not called for extensions and system apps like notes – txulu Oct 10 '17 at 15:16