问题
I want to associate a text-based custom file type with my app on iOS.
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.
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.
On the side note, if I substitute any binary file (zip, ...) and use my extension, file associating will still work.
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>
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"?
回答1:
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.
来源:https://stackoverflow.com/questions/10578951/file-associating-on-ios-opening-a-plain-text-file-from-safari