5

I'm currently using a UIDocumentInteractionController for open in functionality. When it opens it shows a list of all apps on the device that can handle that file type.

Is there a way to disable my app sending a document to specific apps, even if they support that file type? For example - if I have a PDF file open in my app and iBooks is on the iPad, if I tap the iBooks icon in the UIDocumentInteractionController, I don't want it to send it to the app.

Ideally - I see this as building a blacklist (or whitelist). For example, it would be great to do this:

   - (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application {


    // if app is blacklisted
    if ([application isEqualToString:@"com.schimera.WebDAVNavigator"]) {
        [self.interactionController dismissMenuAnimated:YES];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"FAIL" message:@"NO" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];

        return
    }
}

With this however, the document is still sent to the application even if it is "black listed".

Is this approach at all possible?

Cheers!

yodatg
  • 91
  • 1
  • 2
  • 6

2 Answers2

2

Change the UIDocumentInteractionController's URL to an invalid value if the app is blacklisted. In the method -[UIDocumentInteractionControllerDelegate documentInteractionController: willBeginSendingToApplication:].

-(void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application
{
    if([application isEqualToString:@"com.evilcorp.badapp"){
        controller.URL = nil;
    }
}
orkoden
  • 18,946
  • 4
  • 59
  • 50
Karthik
  • 770
  • 1
  • 6
  • 12
  • This doesn't seem to help when you want to restrict "Email" or "Print". – Mustafa Oct 15 '14 at 11:42
  • This leads to crash on iOS 9.3.5 on iPad. CoreFoundation 0x22e9f860 -[NSException initWithCoder:] Foundation 0x2360880c -[NSFileManager fileSystemRepresentationWithPath:] CloudDocs 0x30fd6e46 -[NSString(BRCPathAdditions) brc_pathRelativeToPath:] UIKit 0x27803716 -[NSURL(UIDocumentPicker) ui_canOpenInPlace] UIKit 0x27a8e136 -[UIDocumentInteractionController _openDocumentWithApplication:] UIKit 0x27a88740 -[_UIOpenWithAppActivity performActivity] – Lakshmi Feb 08 '17 at 05:04
-1

To offer open file in a specific app (as white list), just add (using swift 3.0):

docController.uti = @"com.yourapp.package";
Quan Nguyen
  • 5,074
  • 3
  • 24
  • 26