rubyrubymotionrubymotion-promotion

Display content on PM::WebScreen from BubbleWrap response


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

I need to send HTTP request with specific header, but content always nil . I have checked response by sniffer - everything is Ok.

If I do this way

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

I see

eb_screen_module.rb:50:in `set_content:': Is a directory - read() failed (Errno::EISDIR)

exception


Solution

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

    Found solution myself