how to open a file in iWork in the iPad - iphone

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.

Related

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

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.

How to provide one-touch access to a PDF file in the cloud with rich features like annotation?

I need to be able to download a PDF file from a location on the Internet and then open it (just the file, not to a specific page) in an app like Goodreader or even iBooks.
What I originally thought was that I would put an icon on my users' home page that launches a PDF file in an app, similar to how in Safari you can "Add To Home Page" and add a link onto the Home Page. The idea would be to have that functionality but with an, e.g., ibooks:// link rather than an http:// and it would open the pdf being linked to there within iBooks.
I am able to launch Safari to view a PDF using the Add To Home Page function to put an icon on the Home Page pointing to a PDF at a certain URL, so I am wondering if using, e.g. a Scheme definition I can pull it off.
So my solutions so for are:
1) Create a link to the PDF to open in Safari using "Add To Home Page" (offers zero functionality, including the hard requirement of being able to annotate the PDF)
2) Employ a specific App's Custom URL Scheme Definiton with the iPhone Configuration Utility's "Web Clips" create something to the effect of ibooks://www.pdf.com/document.pdf (i dont think this works)
3) Write a custom app and figure out how to do the annotating part myself (Did this using FastPDFKit but it does not include anything for annotating which is really key)
I believe if you put a g infront of the URL when adding to home screen, it will open with GoodReader when launched.

View PDFs and Office Documents from within own App?

I'm planning an iOS application which will allow browsing documents on my server using a WebService. The user will have the option to download documents (PDF and MS Office) to have them available offline.
Now I know that iPhone/iPad is capable of viewing all kinds of document formats, including PDF, DOC(X), XLS(X) if they are received through email for instance. I assume they are all handled by the same "preview module".
The question is: if I have the documents in my app's storage, how can I use the same functionality?
Solution in ObjC or MONOTOUCH is fine, or just pointing my into the right direction in general.
René
You can use the UIDocumentInteractionController which will present the user with a menu offering them "Quick Look" (which will open the file in the app) or the option to open the file in another app depending on what the user has installed.
Same sample code I've used looks like this (where e.Result is the result of a call to my web service).
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string filePath = Path.Combine(path, e.Result.Filename);
if (!File.Exists(filePath))
{
File.WriteAllBytes(filePath, e.Result.DocumentData);
}
UIDocumentInteractionController docControl = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
docControl.Delegate = new UIDocumentInteractionControllerDelegateClass(this);
InvokeOnMainThread(delegate {
docControl.PresentOptionsMenu(new RectangleF(0,-260,320,320), tbnv.View, true);
});
The delegate class contains overrides for the view where the preview view will appear (so you want to pass the current view to this and ensure that this is the view the preview will be presented in).
In my app, I allow users to view PDF's in-app by using a UIWebView control, and just loading the url of the PDF in it. That should work for internal PDFs also. I've never tried it with other types of docs, but I imagine the same approach would work.

is it possible to download a file in my iphone throuh email

I am working on an application in which i write to an xml file and then send it through email and at the reciever end the receiver recives it in his/her inbox and download the file to the iphone and then open the same app on his phone and browse to this file and by clicking sync button the progra should parse the tags in the xml file.
Everything is cler but i am not sure whether we can download a file to our iphone and browse thru it our app.
Thanks, i appreciate. :)
No, I don't believe you can download a file from mail and pass it to your app to open and read. This would be for security reasons.
I think the only way to achieve this would be to not use an XML file, and instead construct a URL with parameters.
There are a few drawbacks here, though. Depending on how much data you need to pass, the url could get pretty large. You would have to take considerations to make sure that each parameter value is properly URL escaped. And you could have to write code to parse the data in the parameters.
This is how other apps pass data between apps, an example would be the iPhone's Phone app. You can make it call a number by using a tel:// URL.
You can register a URL scheme in your app and use it to pass data around.

(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