module BubbleWrap::App
Public Instance Methods
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
Main Screen bounds. Useful when starting the app
# File motion/core/ios/app.rb, line 64 def bounds UIScreen.mainScreen.bounds end
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
@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
Application Delegate
# File motion/core/ios/app.rb, line 69 def delegate UIApplication.sharedApplication.delegate end
# File motion/core/app.rb, line 84 def development? environment == 'development' end
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
the current application environment : development, test, release
# File motion/core/app.rb, line 80 def environment RUBYMOTION_ENV end
Return application frame
# File motion/core/ios/app.rb, line 59 def frame UIScreen.mainScreen.applicationFrame end
# File motion/core/app.rb, line 57 def identifier NSBundle.mainBundle.bundleIdentifier end
# File motion/core/app.rb, line 49 def info_plist NSBundle.mainBundle.infoDictionary end
# File motion/core/app.rb, line 100 def ios? Kernel.const_defined?(:UIApplication) end
# File motion/core/app.rb, line 53 def name info_plist['CFBundleDisplayName'] end
Returns the default notification center @return [NSNotificationCenter] the default notification center
# File motion/core/app.rb, line 23 def notification_center NSNotificationCenter.defaultCenter end
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
# File motion/core/app.rb, line 96 def osx? Kernel.const_defined?(:NSApplication) end
# File motion/core/app.rb, line 92 def release? environment == 'release' end
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
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
# File motion/core/app.rb, line 65 def short_version info_plist['CFBundleShortVersionString'] end
# File motion/core/app.rb, line 45 def states @states end
# File motion/core/app.rb, line 88 def test? environment == 'test' end
# File motion/core/app.rb, line 27 def user_cache NSUserDefaults.standardUserDefaults end
# File motion/core/app.rb, line 61 def version info_plist['CFBundleVersion'] end
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
# File motion/core/ios/app.rb, line 78 def windows UIApplication.sharedApplication.windows end