1

我有一个 pdf 文件,我想用一个特定的应用程序打开,比如 iBooks。我想拥有它,以便用户可以在当前安装的可以处理它的程序中设置他们想要打开它的程序。这是我拥有的代码,可以让我做到这一点,只有用户必须选择每次使用哪个应用程序(我想避免一个额外的步骤):

NSString *stringVariable = cell.textLabel.text;

NSString *homeDir = NSHomeDirectory();
homeDir = [NSString stringWithFormat: @"%@/%@", homeDir, @"Documents"];  
NSString * filePath = [NSString stringWithFormat:@"%@/%@", homeDir, stringVariable]; 

documentController = 
[UIDocumentInteractionController 
interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
documentController.delegate = self;
[documentController retain];
documentController.UTI = @"com.adobe.pdf";
[documentController presentOpenInMenuFromRect:CGRectZero 
                                       inView:self.view 
                                     animated:YES];

因此 stringVariable 包含相关文档的名称,然后显示能够运行它的各种应用程序。如果我能以某种方式将其填充到某种选择器中,以便用户可以选择要使用的默认应用程序,那就太好了,但是如果我必须自己将其设置为特定的应用程序(例如 iBooks),那将起作用也。

4

1 回答 1

0

使用 UTI 参数。例如,如果您有 5 个支持 Instagram url 方案和文件类型的应用程序,只需使用以下命令:

documentController.UTI = @"com.instagram.exclusivegram";

它不会为您做出选择,但会将选择限制在应用程序所需的范围内。

于 2012-11-29T12:01:04.350 回答