How to download PDF to iOS Files app from WKWebView? - ios

I have a website within WKWebView that has a link to open a PDF, I want to intercept this so that it brings up a share sheet to save the PDF to the iPhone files app.
New to swift so unsure how to do this, I've tried many solutions from other answers and whilst https://stackoverflow.com/a/60614921/11868620 works well, it saves it to a Documents folder linked to my app rather than the Downloads folder in the Files app.
How do I implement this functionality?

Related

iOS Files App Registration with file types

I store video files in the Documents folder of my app. I need to present an option that enables users to copy video files from Documents folder to iOS Files app. I also want to automatically have a folder for my app in iOS files app (as seen in the screenshot).
I tried registering Document type "public.movie" (screenshot 2) but didn't help.
Wondering how to achieve it.

Add a file into the ios app

I am a newbie to iOS, I have a created a textfield and imageView in a ViewController. I want user of app to select an image or a file(.txt,.csv, etc)into the App. I know that Apple provides UIImagePicker to select images from the device. with these I added an image to my imageView.
Now I want to Know that is there any way to select files from the device and use it into application. Or else Open file system of device and select the file ?
When I Googled it, I got that you are not able to open the file system. So how can I implement this functionality in iOS app?
There is no way of selecting file from file system into application. You can only access files from
Default Photos App
Application Documents Directory
Any file from web server with use of API's
There are multiple ways from which you can select files of different types other than images are
Integrate Dropbox SDK into app
Integrate Google Drive
Integrate iCloud
So create one UIButton like "Select File" and open UIActionSheet on tap of it. UIActionSheet will have options like
Select From Photos
Select File From Dropbox
Select File From iCloud
Select File From Google Drive
etc
And you can call respective actions on each index.
You can pick your documents and images and other files by using separator picker for each like
for Documents - UIDocumentPickerViewController
for Images/Videos - UIImagePickerController
Apple does not provide a direct picker for all files.
Hope this is working for you. :)
You can use UIDocumentPickerViewController if you enable iCloud document support for your app.
you can not load files directly from file system, but you can load them from some third party applications like Documents and cloud sources like iCloud and Drop Box with UIDocumentPickerViewController

Is there a way to open an editor app in ios and receive edited results?

I have an app that downloads files from a web server. Our customer wants the ability to edit those files on their mobile devices and upload the edited version to our servers. Is this possible in iOS? I have figured out how to allow users to view the files in external apps, but I don't see a way to bring back their changes if the file was modified as it seems to copy the file into the other app's space, so my app is left with the unaltered version.
iOS has a sandbox mechanism, so for sure you can not modify any file in another app.
The only way to transfer data from different app is using sharing.
This is a sample project I wrote for implement sharing on iOS, check it:
Sample for sharing on iOS
Hope it can help you.

Is it possible to load a pdf into my iOS app from iBooks?

I have an app that I'm using to create a custom PDF document (containing an image). I'm using my app the save the PDF into iBooks. I would like to be able to later access iBooks and get a copy of the document again.
I know that because of sandboxing, you used to not be able to load documents from iBooks into my iOS app. However, you weren't able to open PDFs with iBooks before and now you are - so is there a workout around for picking my own PDFs out of iBooks and loading them back into the app?
If not, how would I go about doing this? Are there examples or tutorials somewhere? (I'd like to select my own previously-saved pdf, from the same app, from iBooks like I'm able to select an image from the photo roll)
thank you!
iBooks are developed using iBooks Author, not Xcode. In addition, iBooks are for use with the iBooks application that is available for newer versions of iOS. They are not meant to be used within an iOS application.
So, sorry for the sad news. You can not integrate iBooks with your iOS apps.

Can a PDF downloaded by my iOS app be viewed by iBooks or any other application?

Right now, the PDFs I download on my app are being stored in the app's document directory and can be retrieved only within the app. Is there any way to store the PDF files in the common documents directory that can be accessed by other apps?
If not, is there a way of storing my downloaded PDFs in other apps' documents directory (let's say iBooks), so that it will always be stored in iBooks.
If there are any ways, please elaborate.
There is no "commun documents directory" on iOS, each App is launched in is own sandbox and cannot access the files from other app directly.
I suggest you to check the iOS File System Basics guide from Apple in order to understand better what's happening behind the scenes.
You can still use an UIActivityController in your code to perform an export of your pdf file to iBooks or any app accepting this kind of file, but it requires some user interaction.

Resources