How do I open a file with unknown associations in iOS? - iphone

I think it's rather impossible, but will ask anyway. My application uses file association to open some types of files. What I need is to make file associations within my app. For example I have some files in my app's Documents folder and when user wants to open that it would be a great idea to ask him in which application he would like it to open (like Mail app does).
It can possibly be done with URL schemes, but if I don't know what applications user has, it can't be used. So, is there any way to use the device's file associations within an application?

You should take a look at Document Interaction Programming Topics for iOS. It explains how you can use the UIDocumentInteractionController class to present the user a list of apps which support a given file.

Related

With Chrome Apps soon to be removed, is there another way to edit a local file?

The Chrome Apps API has the very useful FileSystem API which allows a user to select a file for an app to edit (read and write changes to). However, with the entire Apps API soon to be removed, what other ways exists to edit a file on the local file system?
This is not an opinion-based question, I am asking for all conceivable alternatives.
Per https://developers.chrome.com/apps/migration:
Q: My app uses the chrome.fileSystem API to read and write user-specified files and / or directories. Can this be done on the open web?
A: In general, no. The open web can read single files that the user opens, but cannot retain access to those files, write to those files, or have any access to directories.
If it is critical for your app to read and write directories (e.g. it is a text editor with a folder view), you will need to either have a native helper app and extension combo, or create a native app.

What Files can iOS Apps use?

The situation: We would like to make an app that shows all files on an iOS Device
The system: iOS App, non jailbroken system
The question:
What files (and filetypes) are allowed to be accessed by every app (system-wide) ?
(PS: we won't do file-browser like actions like sub-folders, delete, etc .. )
UPDATE :
what you are trying to achieve is not possible because of the sandbox feature of the apps. though you can display certain file types using below description.
Previously Answered this
If I understand your question correctly, there is already a framework for what you are trying to achieve. It is called the quick look framework and supports these many file types...
A Quick Look preview controller can display previews for the following items:
iWork documents
Microsoft Office documents (Office ‘97 and newer)
Rich Text Format (RTF) documents
PDF files
Images
Text files whose uniform type identifier (UTI) conforms to the public.text type (see Uniform Type Identifiers Reference)
Comma-separated value (csv) files
you can have more info about it here...
You can't access anything other than your application folder. Your application is sandboxed and for good reasons (privacy, malware, etc...)
You can only access files within your application directory. Look here for a full explanation
If you don't mean files and just the content of the phone, there are APIs for
Photos
Contacts
Media from the Music app

How can I read documents from other iOS apps?

I have an app which is similar to an FTP client. I can download various types of documents in it. (DOC, XLS, PDF, PPT etc)
Now, I want to read those documents in another application. For example: Suppose I download a PDF in my app, it is possible to read from AirSharing or File Magnet?
I don't think it's possible for other applications to access Library folders owned by other apps, and definitely not private application folders.
Document handling might handle what you want only to an extent - not the files that don't have their types registered to any app, and only at a one by one file basis, essentially duplicating the files as well.
If this is your app you are talking about, you can implement the Open In feature which is part of the Document Interaction in iOS, which will allow the user to access the file in any app that is registered to handle the extension/UTI.
In particular, these methods:
UIDocumentInteractionController
– presentOpenInMenuFromRect:inView:animated:
– presentOpenInMenuFromBarButtonItem:animated:

(Iphone) associate an App to some file extension to open email attachments in Mail app

I found that some application, like "GoodReader" or "Docs to Go", once installed can be activated using the "Open in" function when opening an email attachment in the Mail App. How to add this function to have my App to be associated to some kind of documents (like pdf) ?
The idea is to have an easy way to get mail attachments to be used directly inside an app.
Edit: I found this document and think it fits my question:
Document Support
An application can now register the file types it supports with the system and receive notifications when a file of the given type needs to be opened. It does this by including the CFBundleDocumentTypes key in its Info.plist file. An application that registers one or more file types may also be expected to open files of those types at some point later. It does this by implementing the
application:didFinishLaunchingWithOptions:method in its application delegate and look for a file
in the UIApplicationLaunchOptionsURLKey key of the provided dictionary.
Complementing the ability to open files of known types is the addition of the
UIDocumentInteractionControllerclass in the UIKit framework. This class provides a user-based
interaction model for managing files that your application does not know how to open. The document
interaction controller provides options for previewing the contents of a file in place or opening it in another
application. Document interaction controllers are particularly useful for email applications or applications
that may download files from the network.
take a look at Custom URL Schemes and UIDocumentInteractionController. If you are looking to add the "open in" menu, the second link is what you need. If you are looking to register as a "PDF reader" this link (scroll to section about registering your app for certain types) should work iPad Programming Guide

how to open a file in iWork in the iPad

From what I understand, UIApplication -openFile can open files externally, the application depending on the URL scheme. Say I have a pages (or word maybe?) document, and I want to open it in pages from my app. Does anyone know the URL scheme for me to do that? Is there a list anywhere? (Keynote, and Numbers would also be useful).
It doesn't work that way because you cannot transmit the file via a URL and Pages cannot access a file that is stored in your app's sandbox.
If you want to give the user the option to open a file in Pages in your UI, UIDocumentInteractionController is the way to do that. It presents a UI where the user can preview the file and select to open it in any application that supports the file type.
AFAIK it is not possible with the SDK to do this completely programmatically, i.e. without user interaction.