UIDocumentInteractionController在某些应用程序中禁用打开

我目前正在使用UIDocumentInteractionController来打开function。 当它打开时,它会显示设备上可以处理该文件类型的所有应用程序的列表。

有没有办法禁用我的应用程序将文档发送到特定的应用程序,即使他们支持该文件类型? 例如 – 如果我在我的应用程序中打开了PDF文件而iBooks在iPad上,如果我点击UIDocumentInteractionController中的iBooks图标,我不希望它将其发送到应用程序。

理想情况下 – 我将此视为构建黑名单(或白名单)。 例如,这样做会很棒:

- (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 } } 

但是,即使它被“黑名单”,文档仍然会被发送到应用程序。

这种方法有可能吗?

干杯!

如果应用程序被列入黑名单,请将UIDocumentInteractionController的URL更改为无效值。 在方法中-[UIDocumentInteractionControllerDelegate documentInteractionController: willBeginSendingToApplication:]

 -(void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application { if([application isEqualToString:@"com.evilcorp.badapp"){ controller.URL = nil; } } 

要在特定应用程序中提供打开文件(作为白名单),只需添加(使用swift 3.0):

 docController.uti = @"com.yourapp.package";