文件在iOS上关联 - 从Safari打开纯文本文件 [英] File associating on iOS - opening a plain-text file from Safari

查看:156
本文介绍了文件在iOS上关联 - 从Safari打开纯文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS上将基于文本的自定义文件类型与我的应用相关联。

I want to associate a text-based custom file type with my app on iOS.

当我打开一个指向某个php脚本后面的文件的链接时, Safari在我的应用程序中显示打开选项,这没关系。

When I open a link to the file which is behind some php script, Safari shows the "open in" option with my app in it, which is OK.

但是当我打开直接指向我的文件的链接时(运行Web服务器)为了测试目的),Safari决定它可以自己读取文件并自己显示内容。这绝对不行。

However when I open a link which points directly to my file (running a web server for test purposes), Safari decides that it can read the file itself and displays the content by itself. Which is definitely not OK.

在旁注中,如果我替换任何二进制文件(zip,...)并使用我的扩展名,文件关联仍然有效。

On the side note, if I substitute any binary file (zip, ...) and use my extension, file associating will still work.

plist-info中的代码:

The code in plist-info:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>320.png</string>
            <string>64.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>My File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.Company.Product.ext</string>
        </array>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
            <string>public.content</string>
            <string>public.text</string>
            <string>public.plain-text</string>
            <string>public.utf16-plain-text</string>
            <string>public.utf16-external-plain-text</string>
            <string>public.utf8-plain-text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>My File</string>
        <key>UTTypeIdentifier</key>
        <string>com.Company.Product.ext</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>ext</string>
            <key>public.mime-type</key>
            <string>application/octet-stream</string>
        </dict>
    </dict>
</array>

我的问题是:如何说服Safari不打开文件本身?它甚至可能吗?我是否必须使用application / octet-stream以外的某些mime类型?

My question is: how to persuade Safari to NOT open the file itself? It it even possible? Do I have to use some mime type other than "application/octet-stream"?

推荐答案

定义自定义MIME类型(即文件的 application / x-my.custom.type ),并让PHP或您的Web服务器为它们提供服务。这应该有所帮助。

Define a custom MIME type (i.e. application/x-my.custom.type) for your files, and have PHP or your web server serve them. This should help.

这篇关于文件在iOS上关联 - 从Safari打开纯文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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