繁体   English   中英

iOS“添加到主屏幕” - 文件下载将用户踢出

[英]iOS “Add to Home Screen” - file download kicks user out

我需要一个有效的会话才能从我的网络应用程序下载文件。

当我在iOS设备上打开我的网络应用程序,登录并尝试从我的网站下载文件(PDF)时,我被踢出去并在Safari中打开链接。 用户必须再次从Safari登录才能下载页面。

如何强制文件在Web应用程序中打开并在那里触发下载表单?

我正在使用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

更新:我发现半工作解决方案直接在浏览器中打开文件:

$(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

通过使用这个代码片段中,我们强制iOS用户在全屏模式(Web应用程序)运行打开所有a应用程序中的链接。 但问题是,如果用户打开文件,则不会出现“后退”按钮。 由于iPhone用户缺少物理后退按钮,他们将不得不强制重启整个应用程序以退出显示的文件。

使用您发布的代码,但不是将整个页面内容写入正文,您可以在单独的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

我发现半工作解决方案直接在浏览器中打开文件:

$(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

通过使用此代码片段,我们强制iOS用户以全屏模式(Web应用程序)运行,以打开应用程序内的所有链接。 但问题是,如果用户打开文件,则不会出现“后退”按钮。 由于iPhone用户缺少物理后退按钮,他们将不得不强制重启整个应用程序以退出显示的文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM