IOS "Add to Home Screen" - file download

I need to have a valid session to download files from my web application.

When I open my web application on my iOS device, log in and try downloading the file (PDF) from my site, I will be kicked out and the link will open in Safari. To load the page, the user needs to log in again from Safari.

How to make a file open in a web application and run a download form instead?

I use Carrierwave and in the controller I have this to start the download:

class DocumentsController < ApplicationController # .. code omitted def download if @document.name.file.exists? send_file @document.name.path, x_sendfile: true else redirect_to documents_url, notice: t(:file_not_found) end end end 

UPDATE: I found a semi-working solution that opens the file directly in the browser:

 $(document).ready -> if 'standalone' of window.navigator and window.navigator.standalone # For iOS Apps $('a').on 'click', (e) -> e.preventDefault() new_location = $(this).attr('href') if new_location != undefined and new_location.substr(0, 1) != '#' and $(this).attr('data-method') == undefined window.location = new_location return return 

Using this piece of code, we force iOS users to work in full screen mode (web application) to open all a links inside the application. The problem is that if the user opens the file, there will be no “back” -button. And since iPhone users lack the physical back button, they will have to force restart the entire application to exit the file shown.

+6
source share
2 answers

Use the code that you posted, but instead of writing the entire content of the page to the body, you can enter it in a separate div and make sure that there is a back button that is available only for iOS devices:

 $(document).ready -> if 'standalone' of window.navigator and window.navigator.standalone # For iOS Apps $('a').on 'click', (e) -> e.preventDefault() new_location = $(this).attr('href') if new_location != undefined and new_location.substr(0, 1) != '#' and $(this).attr('data-method') == undefined window.location = new_location return return 
+2
source

I found a semi-working solution that opens the file directly in the browser:

 $(document).ready -> if 'standalone' of window.navigator and window.navigator.standalone # For iOS Apps $('a').on 'click', (e) -> e.preventDefault() new_location = $(this).attr('href') if new_location != undefined and new_location.substr(0, 1) != '#' and $(this).attr('data-method') == undefined window.location = new_location return return 

Using this piece of code, we force iOS users to work in full screen mode (web application) to open all the links within the application. The problem is that if the user opens the file, there will be no “back” -button. And since iPhone users lack the physical back button, they will have to force restart the entire application to exit the file shown.

+1
source

All Articles