从BubbleWrap响应显示PM :: WebScreen上的内容

时间:2017-01-19 17:53:41

标签: ruby rubymotion rubymotion-promotion

class WorkoutScreen < PM::WebScreen
  title "Workouts"

  def content
    @response
  end

  def on_load
    set_nav_bar_button :left, title: "Menu", action: :nav_left_button
  end

  def load_started
    @response = ''
    BubbleWrap::HTTP.get("my_url", {async: false, :headers => { "User-Agent" => "value"}}) do |response|
      @response = response.body.to_str
    end
  end

  def nav_left_button
    app_delegate.menu.show(:left)
  end
end

我需要发送带有特定标头的HTTP请求,但内容总是为零。我已经通过嗅探器检查了响应 - 一切都很好。

如果我这样做

class WorkoutScreen < PM::WebScreen
  title "Workouts"

  def content
    @response = ''
    BubbleWrap::HTTP.get("my_url", {async: false, :headers => { "User-Agent" => "value"}}) do |response|
      @response = response.body.to_str
    end
    @response
  end

我看到了

  

eb_screen_module.rb:50:在`set_content:':目录 - 读取()失败(Errno :: EISDIR)

例外

1 个答案:

答案 0 :(得分:1)

NSUserDefaults.standardUserDefaults.registerDefaults({UserAgent: "value"})

自己找到解决方案