【问题标题】:iOS “Add to Home Screen” - file download kicks user outiOS“添加到主屏幕” - 文件下载将用户踢出
【发布时间】:2015-09-01 13:27:34
【问题描述】:

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

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

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

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

通过使用这个 sn-p 代码,我们强制运行在全屏模式(网络应用)的 iOS 用户打开应用内的所有 a 链接。但问题是,如果用户打开文件,将没有“后退”按钮。由于 iPhone 用户缺少物理后退按钮,他们将不得不强制重启整个应用程序才能退出显示的文件。

【问题讨论】:

标签: ios ruby-on-rails download carrierwave iphone-standalone-web-app


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我找到了直接在浏览器中打开文件的半工作解决方案:

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

    通过使用这个 sn-p 代码,我们强制运行在全屏模式(网络应用)的 iOS 用户打开应用内的所有链接。但问题是,如果用户打开文件,将没有“后退”按钮。由于 iPhone 用户缺少物理后退按钮,他们将不得不强制重启整个应用程序才能退出显示的文件。

    【讨论】:

      猜你喜欢
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 2018-10-27
      • 2013-08-14
      • 1970-01-01
      • 2019-11-21
      相关资源
      最近更新 更多