openURL本地文件或强制UIDocumentInteractionController使用特定的应用程序 [英] openURL a local file or force UIDocumentInteractionController to use a specific app

查看:160
本文介绍了openURL本地文件或强制UIDocumentInteractionController使用特定的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用另一个应用程序打开一个文件(存储在我的应用程序中)。

I wish to open a file (stored locally in my app) with another app.

目前,我正在使用openURL(有一个专用的url方案),如果我使用托管在互联网上的文件,它工作正常,但我想使用本地文件,因此:
a)它可以离线工作
b)很多时候我的用户要么不在区域覆盖,或国际漫游

Currently, I am using openURL (there is a dedicated url scheme), and it works fine if I use a file hosted on the internet, but I would like to use a local file so: a) it works offline b) a lot of the time my users are either out of cell zone coverage, or roaming internationally

到目前为止我尝试过:
我没有运气告诉openURL使用本地文件,我试过了很少的方法,但它们都是这样的

What I have tried so far: I have not had any luck telling openURL to use a local file, I have tried a few approaches but they are all something like this

      NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"ext"];
      NSURL *fileURL = [NSURL fileURLWithPath:filePath];
      [[UIApplication sharedApplication] openURL:fileURL];

      NSURL *fileURL = [[NSBundle mainBundle] URLForResource: @"test" withExtension:@"ext"];
      [[UIApplication sharedApplication] openURL:fileURL];

还手动使用具有localhost /和file://和var / mobile等路径的不同变体的字符串

also manually using strings with different variations of localhost/ and file:// and var/mobile etc paths

无论如何都没有用(对我来说)

nothing works (for me anyway)

所以,我环顾四周并遇到了 UIDocumentInteractionController

So, I looked around SO and came across UIDocumentInteractionController

我可以使用UIDocumentInteractionController让用户使用其他应用程序打开我的本地文件 - 但是它总是提供其他应用程序的多个选项供使用,例如,其他应用程序之一可以是'Dropbox '。

I am able to use UIDocumentInteractionController to let the user open my local file with the other app - however it always present multiple options of other apps to use and for example, one of the other apps can be 'Dropbox'.

我不想让用户下载(或技术上传)我的文件副本以供其他方式使用。它包含我不希望随时可用的数据。

I do not want to let the user download (or upload technically) a copy of my file for their use in other ways. It contains data that I would prefer not to make so readily available.

当我的预期应用程序打开文件时(不是我用btw制作)它不允许任何保存或访问原始数据。

When the file is opened by my intended app (not made by me btw) it does not allow any kind of saving or access to raw data.

我意识到通过在我的应用程序中包含该文件,任何认真获取它的人都可以,我只是不要我想闪现一个大菜单,上面写着'如果你想要自己的副本来制作衍生作品,那就是'

I realize that by including the file in my app anyone who is serious about obtaining it will be able to, I just don't want to flash a big menu saying 'Here it is if you want your own copy to make derivative work from'

理想情况下,我可以使用openURL,但我认为它是因为其他应用程序没有响应的沙盒 - 在Android中我使用mode_world_readable将文件声明为其他应用程序可读(因此将其放在沙箱之外,并且它不允许其他应用程序写入,只是阅读) - 无论如何都要对iOS做同样的事情?

Ideally, I could use openURL but I think it is because of the 'sandbox' that the other app doesn't respond - in Android I use mode_world_readable to declare the file as readable by other apps (therefore placing it outside the sandbox, and it doesn't allow other apps to write to it, just read) - is there anyway of doing the same with iOS?

否则,如果我可以强制UIDocumentInteractionController使用特定的应用程序而不显示菜单 - 那将是很好。

Otherwise, if I could force UIDocumentInteractionController to use a specific app and not present the menu - that would be fine too.

类似的问题前一段时间问

对于长时间阅读感到抱歉,任何帮助都表示赞赏。

Sorry about the long read, any help is appreciated.

编辑:
我刚刚收到Apple Tech支持的答复,他们告诉我这是目前不可能的(就在iOS 6发布之后)

I just received an answer from Apple Tech support and they told me that this is currently impossible (just after iOS 6 released)

推荐答案

是的,你因为严格的沙盒而受到限制iOS版。以下是一些想法。

Yes, you're limited because of the strict sandboxing on iOS. Here are some thoughts.

您可以通过子类化QLPreviewController来覆盖UIDocumentInteractionController的功能。然后,您可以替换显示打开方式菜单的标准栏按钮项目。看一下这篇文章,找到一个子类化QLPreviewController的解决方案: QLPreviewController删除或添加UIBarButtonItems

You can override the functionality of the UIDocumentInteractionController by instead subclassing QLPreviewController. You can then replace the standard bar button item that displays the "Open in" menu. Take a look at this post for one solution for subclassing QLPreviewController: QLPreviewController remove or add UIBarButtonItems

当然,我认为应用程序间共享的工作方式很大程度上取决于你的手。如果某个应用程序已注册为能够处理某种类型的文件,则它将显示为打开列表中的一个选项,无论您是否想要它。我不相信你可以过滤哪个应用程序显示在该列表中。

Of course, I believe the way inter-app sharing works is largely out of your hands. If an app has registered to be able to handle a certain type of file, it is going to display as one of the choices in the "open in" list whether you want it to or not. I don't believe you can filter which apps display in that list.

以下是我考虑过但从未尝试过的两个实验性想法:

Here are two experimental ideas I've thought about but have never tried:


  • 您可以对您尝试传递的文件中的数据进行base64编码 - 这只是将二进制文件转换为文本 - 然后将其关闭作为用于启动其他应用的自定义网址的一部分。然后另一个应用程序可以base64解码相同的数据回二进制。缺点是URL的长度有限,这意味着您发送的文件必须非常小。

  • You could base64 encode the data from the file you're trying to pass along--which just converts binary to text--and hand that off as part of the custom URL you use to launch the other app. Then the other app can base64 decode that same data back into binary. The down side there is that there is a limit to the length of the URL which means the "file" you're sending would have to be pretty small.

接下来,我甚至不知道这是否可行,但我想知道你是否可以使用一些 steganograhpy 算法将文档数据嵌入图像中,然后将其移交给相机胶卷。然后,另一个应用程序可以打开相机胶卷并再次将图像解码回数据。 ......是的我知道......模糊不清,但尝试实施可能会很有趣。 ; - )

Next, and I don't even know if this is possible, but I wonder if you could use some steganograhpy algorithm to embed the document data inside an image and then hand that off to the camera roll. Then, the other app could open the camera roll and decode the image back into the data again. ... Yeah. I know... obscure, but it might be fun to try to implement. ;-)

不确定是否有任何帮助,但你确实说赞赏任何帮助。 ; - )

Not sure if any of that helps, but you did say "any help is appreciated". ;-)

祝你好运。

这篇关于openURL本地文件或强制UIDocumentInteractionController使用特定的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆