关于ios:UIDocumentInteractionController禁用某些应用程序中的打开

UIDocumentInteractionController disable open in certain apps

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

是否可以禁用我的应用程序向特定应用程序发送文档,即使它们支持该文件类型?例如-如果我在应用程序中打开了PDF文件,而iBooks在iPad上,则如果我点击UIDocumentInteractionController中的iBooks图标,则不希望它发送给应用程序。

理想情况下-我认为这是在建立黑名单(或白名单)。例如,这样做很好:

1
2
3
4
5
6
7
8
9
10
11
12
   - (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:]

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


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

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