gpt4 book ai didi

ios - 过滤 UIDocumentInteractionController 建议打开方式的应用程序

转载 作者:行者123 更新时间:2023-11-29 12:38:28 26 4
gpt4 key购买 nike

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

我需要类似的东西

-(BOOL)shouldPresentForOpenInApplication: (NSString *)

最佳答案

其实我想出了怎么做。这有点像把戏,但它确实有效。您需要做的就是实现委托(delegate)的方法,就像这样

- (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 来欺骗文档 Controller 的实际方法。

-(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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com