过滤UIDocumentInteractionController建议打开的应用程序

时间:2014-09-03 15:18:13

标签: ios objective-c uidocumentinteraction

是否可以管理UIDocumentInteractionController将用于打开我的文件的应用程序列表?实际上,我需要创建黑白应用程序列表。  我看了一下UIDocumentInteractionControllerDelegate,但它并没有包含所需的方法..只是 - (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application

我需要像

这样的东西

-(BOOL)shouldPresentForOpenInApplication: (NSString *)

1 个答案:

答案 0 :(得分:1)

实际上我想出了怎么做。 这有点像技巧,但它的工作原理。 您需要做的就是实现委托的方法,如此

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

我们通过替换bad url来欺骗doc控制器的实际方法。

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