UIDocumentInteractionController

UIDocumentInteractionController

是否可以管理UIDocumentInteractionController要在其中打开文件的应用程序列表?实际上,我需要创建应用程序的黑白列表。
我看了看UIDocumentInteractionControllerDelegate,但是它不包含所需的方法。- (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application
我需要类似的东西
-(BOOL)shouldPresentForOpenInApplication: (NSString *)

最佳答案

其实我想出了办法。
这有点像个把戏,但确实有效。
您需要做的就是实现委托的方法,就像这样

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

以及通过替换错误的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];
}

关于ios - 筛选UIDocumentInteractionController建议打开的应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25648023/

10-10 10:48