0

The Apple Docs say that UIDocumentInteractionController "provides in-app support for managing user interactions with files in the local system". Is there a similar setup for viewing files on a server? I tried just sending the link to the file as the NSURL for interactionControllerWithURL:, but that didn't work. I guess the alternative would be to download the file, then open it once it has downloaded, then delete the file. That seems like a lot of extra coding work though, if there is an easier way that's already available.


Edit: I already know the name of the file I want to view/download, so I'm not really looking for the "file list" aspect of UIDocumentInteractionController. On the server, there are many Google Earth .kml files. The user isn't going to directly select which file to open from a list - I select the file to open programmatically based on actions taken by the user previously in the session.

As I understand it, presentOpenInMenuFromRect:inView:animated: will show a popover something like "Would you like to open the file 'myFile.kml' in Google Earth?". If the user selects 'Yes', the UIDocumentInteractionController launches Google Earth and opens myFile.kml. So I guess I'm not really looking for a file list viewer, just a way to trigger an "Open With" kinda functionality, where the file I'm opening exists on my server.

4

2 回答 2

1

UIDocumentInteraction 控制器不能用于查看服务器上存在的文件列表。UIDocument 交互控制器获取源应用程序中存在的本地文件,并显示可以打开该文件的应用程序列表。一旦使用单击文件,则将其传输到目标应用程序。

如果您想从服务器获取文件,那么您可以使用 NSURLConnection 类下载文件表单服务器并将其存储在设备上。

于 2013-08-26T16:04:56.337 回答
0

我想我想通了。我根本不需要使用 aUIDocumentInteractionController来寻找我正在寻找的东西。我可以简单

NSURL *url = [NSURL URLWithString:@"comgoogleearth://www.mysite.com/myfile.kml"];

BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
if (canOpen)
{
    [[UIApplication sharedApplication] openURL:url];
}
else
{
    NSLog (@"Open failed. Make sure Google Earth is installed and the URL is correct.");
}

这将使用我的文件启动 Google 地球,就像我正在寻找的那样。

仅供参考,我从elpsk 对这个问题的回答中得到了谷歌地球的方案。它看起来像是一个包含许多文件类型和打开它们的应用程序的非常全面的列表。只需将comgoogleearth我的 URL 中的 替换为您尝试打开文件的任何应用程序的方案。

于 2013-08-26T17:00:24.400 回答