[英]iOS “Add to Home Screen” - file download kicks user out
I'm requiring a valid session in order to download files from my web app. 我需要一个有效的会话才能从我的网络应用程序下载文件。
When I open my web app on my iOS device, sign-in and try to download a file (PDF) from my site, I get kicked out and the link is opened in Safari instead. 当我在iOS设备上打开我的网络应用程序,登录并尝试从我的网站下载文件(PDF)时,我被踢出去并在Safari中打开链接。 The user have to login again from Safari in order to download the page.
用户必须再次从Safari登录才能下载页面。
How can I force the file to open in the web app and trigger the download form there instead? 如何强制文件在Web应用程序中打开并在那里触发下载表单?
I'm using Carrierwave and in the controller I have this to trigger a download: 我正在使用Carrierwave,在控制器中我有这个触发下载:
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 half-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
By using this snippet of code, we force iOS users running in fullscreen-mode (web app) to open all a
links inside the app. 通过使用这个代码片段中,我们强制iOS用户在全屏模式(Web应用程序)运行打开所有
a
应用程序中的链接。 The problem though is that if a user opens a file, there will be no "back"-button. 但问题是,如果用户打开文件,则不会出现“后退”按钮。 And since iPhone users are missing a physical back button, they will have to force restart the entire app in order to get out of the showed file.
由于iPhone用户缺少物理后退按钮,他们将不得不强制重启整个应用程序以退出显示的文件。
Use the code that you posted but instead of writing the entire page content to the body, you could enter it inside a separate div and make sure that there is a "back" button available only for iOS devices: 使用您发布的代码,但不是将整个页面内容写入正文,您可以在单独的div中输入它,并确保只有iOS设备有“后退”按钮:
$(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
I found half-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
By using this snippet of code, we force iOS users running in fullscreen-mode (web app) to open all a links inside the app. 通过使用此代码片段,我们强制iOS用户以全屏模式(Web应用程序)运行,以打开应用程序内的所有链接。 The problem though is that if a user opens a file, there will be no "back"-button.
但问题是,如果用户打开文件,则不会出现“后退”按钮。 And since iPhone users are missing a physical back button, they will have to force restart the entire app in order to get out of the showed file.
由于iPhone用户缺少物理后退按钮,他们将不得不强制重启整个应用程序以退出显示的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.