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.
Related
How to show application icon in mail document forward actionsheet as shown below.
Description :
Any Document in Mail attachement.
Press and hold until you see action sheet like below image.
Please help me to show my application icon in this action sheet.
Your question is not clear.
Probably you are looking for UIDocumentInteractionController.
UIDocumentInteractionController allows your app to integrate with documents of specified format.
Check these tutorials :
Previewing Documents
Sharing Data
Import/Export Documents
You want to register your application for the file types you are able to receive. Documentation here:
http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html
To declare its support for file types, your app must include the CFBundleDocumentTypes key in its Info.plist property list file. (See “Core Foundation Keys”.) The system adds this information to a registry that other apps can access through a document interaction controller.
I have developed the asp.net mvc application. my one form have the file upload control. so in details view i want to implement the facility to view the uploaded document in browser itself. it should not ask for download and should not open MS office instance to open document. its a user req. It should opens in view mode in browser itself. what code i have to do ? I am using C# as language.
It is not straight forward. For images you can use <img>tag and link to the location in server where you saved the uploaded image. That should work.
However ASFAIK showing the doc/docx things in web page itself is not possible. You will have to employ some third party control to achieve that. Search google to find such controls. May come at a cost.
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:
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
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.