是否可以管理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];
}