Ne AS
Ne AS

Reputation: 1550

Swift: download and open pdf file

Excuse me if it's a stupid question but I didn't find an answer: what's the default pdf reader in iPhone? Is it iBooks for all iPhones? I ask about this because in my swift application I want to download a pdf file then open it by the default pdf reader (or another application) of the device. Still now I can do that with to ways: the first is when the button "Download" is tapped, I let the user choose the way of downloading the file via UIDocumentInteractionController then he can import it using iBooks, Documents, Chrome... I tested it and it works perfectly. The second way is to download the file inside the application (I got the example from the answer of this question) then open it by a pdf reader (the default native one if this is possible).

Any suggestions please?

Upvotes: 3

Views: 10847

Answers (1)

jjs
jjs

Reputation: 1340

If the PDF is available on the web, would it be enough to open it in the browser? This would be a trivially simple method:

if let url = URL(string: "http://path.to/your.pdf") {
    UIApplication.shared.open(url)
}

Safari also offers the option to open the file in another app, if the user wants to use something else.

Upvotes: 2

Related Questions