willBeginSendingToApplication not called when open

2019-06-11 14:03发布

问题:

I have a feature to open docs in other apps from iPhone and iPad app. Also a flag is set whether to allow this action or not. Few apps can be white listed.

When any app is chosen to open doc

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

is called.

In this method I can check whether to allow for chosen app or not.

Issue is for Note, Evernote we get two options 1- its extension 2- Open in. Above method is called for 2 option. But extensions are launched directly.

I din't found any other delegate method called for this.

回答1:

Hopefully you figured something out, but my org faced a similar issue and the MDMs we work with don't have an easy solution. We've decided on the following approach.

  • Always use UIDocumentInteractionController instead of UIActivityViewController

  • Whenever UIDocumentInteractionController is opened reinit and set the URL to dummy content

  • Conform to UIDocumentInteractionControllerDelegate and check the application parameter in willBeginSendingToApplication against your whitelist

  • If application is part of the whitelist then change the value of controller.url to the correct content

The downsides of this approach are that only open-in will work (extensions will always get dummy content) and the user experience isn't great. But if you're building an enterprise app and must prevent data leakage then this is probably the safest way to go.

You can also check out this article for private APIs to hide third-party apps and extensions, mostly in UIActivityViewController:

How to exclude Notes and Reminders apps from the UIActivityViewController?

Unfortunately the way this works seems to have changed between iOS 8 and 9, and again with 10, so it's not optimal. I recommend passing dummy content.