module BubbleWrap::App

Public Instance Methods

alert(title, *args) { |alert| ... } click to toggle source

Displays a UIAlertView.

title - The title as a String. args - The title of the cancel button as a String, or a Hash of options.

(Default: { cancel_button_title: 'OK' })
cancel_button_title - The title of the cancel button as a String.
message             - The main message as a String.

block - Yields the alert object if a block is given, and does so before the alert is shown.

Returns an instance of BW::UIAlertView

# File motion/core/ios/app.rb, line 38
def alert(title, *args, &block)
  options = { cancel_button_title: 'OK' }
  options.merge!(args.pop) if args.last.is_a?(Hash)

  if args.size > 0 && args.first.is_a?(String)
    options[:cancel_button_title] = args.shift
  end

  options[:title]               = title
  options[:buttons]             = options[:cancel_button_title]
  options[:cancel_button_index] = 0 # FIXME: alerts don't have "Cancel" buttons

  alert = UIAlertView.default(options)

  yield(alert) if block_given?

  alert.show
  alert
end
bounds() click to toggle source

Main Screen bounds. Useful when starting the app

# File motion/core/ios/app.rb, line 64
def bounds
  UIScreen.mainScreen.bounds
end
can_open_url(url) click to toggle source

Returns whether an app can open a given URL resource (string or instance of `NSURL`) Useful to check if certain apps are installed before calling to their custom schemas. Usage Example:

App.open_url("fb://profile") if App.can_open_url("fb://")
# File motion/core/ios/app.rb, line 21
def can_open_url(url)
  unless url.is_a?(NSURL)
    url = NSURL.URLWithString(url)
  end
  UIApplication.sharedApplication.canOpenURL(url)
end
current_locale() click to toggle source

@return [NSLocale] locale of user settings

# File motion/core/app.rb, line 70
def current_locale
  languages = NSLocale.preferredLanguages
  if languages.count > 0
    return NSLocale.alloc.initWithLocaleIdentifier(languages.first)
  else
    return NSLocale.currentLocale
  end
end
delegate() click to toggle source

Application Delegate

# File motion/core/ios/app.rb, line 69
def delegate
  UIApplication.sharedApplication.delegate
end
development?() click to toggle source
# File motion/core/app.rb, line 84
def development?
  environment == 'development'
end
documents_path() click to toggle source

Returns the application's document directory path where users might be able to upload content. @return [String] the path to the document directory

# File motion/core/app.rb, line 11
def documents_path
  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
end
environment() click to toggle source

the current application environment : development, test, release

# File motion/core/app.rb, line 80
def environment
  RUBYMOTION_ENV
end
frame() click to toggle source

Return application frame

# File motion/core/ios/app.rb, line 59
def frame
  UIScreen.mainScreen.applicationFrame
end
identifier() click to toggle source
# File motion/core/app.rb, line 57
def identifier
  NSBundle.mainBundle.bundleIdentifier
end
info_plist() click to toggle source
# File motion/core/app.rb, line 49
def info_plist
  NSBundle.mainBundle.infoDictionary
end
ios?() click to toggle source
# File motion/core/app.rb, line 100
def ios?
  Kernel.const_defined?(:UIApplication)
end
name() click to toggle source
# File motion/core/app.rb, line 53
def name
  info_plist['CFBundleDisplayName']
end
notification_center() click to toggle source

Returns the default notification center @return [NSNotificationCenter] the default notification center

# File motion/core/app.rb, line 23
def notification_center
  NSNotificationCenter.defaultCenter
end
open_url(url) click to toggle source

Opens an url (string or instance of `NSURL`) in the device's web browser or in the correspondent app for custom schemas Usage Example:

App.open_url("http://matt.aimonetti.net")
App.open_url("fb://profile")
# File motion/core/ios/app.rb, line 10
def open_url(url)
  unless url.is_a?(NSURL)
    url = NSURL.URLWithString(url)
  end
  UIApplication.sharedApplication.openURL(url)
end
osx?() click to toggle source
# File motion/core/app.rb, line 96
def osx?
  Kernel.const_defined?(:NSApplication)
end
release?() click to toggle source
# File motion/core/app.rb, line 92
def release?
  environment == 'release'
end
resources_path() click to toggle source

Returns the application resource path where resource located @return [String] the application main bundle resource path

# File motion/core/app.rb, line 17
def resources_path
  NSBundle.mainBundle.resourcePath
end
run_after(delay,&block) click to toggle source

Executes a block after a certain delay Usage example:

App.run_after(0.5) {  p "It's #{Time.now}"   }
# File motion/core/app.rb, line 35
def run_after(delay,&block)
  NSTimer.scheduledTimerWithTimeInterval( delay,
                                          target: block,
                                          selector: "call:",
                                          userInfo: nil,
                                          repeats: false)
end
shared() click to toggle source

the Application object.

# File motion/core/ios/app.rb, line 74
def shared
  UIApplication.sharedApplication
end
short_version() click to toggle source
# File motion/core/app.rb, line 65
def short_version
  info_plist['CFBundleShortVersionString']
end
states() click to toggle source
# File motion/core/app.rb, line 45
def states
  @states
end
test?() click to toggle source
# File motion/core/app.rb, line 88
def test?
  environment == 'test'
end
user_cache() click to toggle source
# File motion/core/app.rb, line 27
def user_cache
  NSUserDefaults.standardUserDefaults
end
version() click to toggle source
# File motion/core/app.rb, line 61
def version
  info_plist['CFBundleVersion']
end
window() click to toggle source

the Application Window

# File motion/core/ios/app.rb, line 83
def window
  normal_windows = App.windows.select { |w|
    w.windowLevel == UIWindowLevelNormal
  }

  key_window = normal_windows.select {|w|
    w == UIApplication.sharedApplication.keyWindow
  }.first

  key_window || normal_windows.first
end
windows() click to toggle source
# File motion/core/ios/app.rb, line 78
def windows
  UIApplication.sharedApplication.windows
end