2014-09-03 46 views
1

是否有可能管理UIDocumentInteractionController將用於打開我的文件的應用程序列表?其實,我需要創建黑白名單的應用程序。 我看了看UIDocumentInteractionControllerDelegate,但它不包含所需的methods..only
- (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application過濾UIDocumentInteractionController建議打開的應用程序

,我需要這樣的東西

-(BOOL)shouldPresentForOpenInApplication: (NSString *)

+0

你是什麼意思「創建黑白名單」?不,你不能過濾應用程序列表。它基於共享文檔的UTI。 – rmaddy 2014-09-03 15:51:32

+0

這意味着用戶可以阻止某些應用在列表中顯示。建議的應用程序的順序是由白名單(來自白名單的應用程序首先)來管理的,希望你明白我在說什麼。 – Stas 2014-09-04 08:33:49

回答

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

和我們欺騙代不良網址的文檔控制的實際方法。

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

你可以在這裏粘貼整個代碼嗎? @Stas – 2016-01-03 13:51:45

+0

好吧,這就是所有要使用的代碼。 – Stas 2016-01-12 12:05:46

+0

這種方法不會一直工作,因爲'willBeginSendingToApplication'不會被用於擴展和系統應用程序,如筆記 – txulu 2017-10-10 15:16:29

相關問題