Module: BubbleWrap::App
- Includes:
- Deprecated
- Defined in:
- motion/core/app.rb,
motion/core/osx/app.rb,
motion/core/ios/app.rb
Class Method Summary collapse
-
.alert(title, *args) {|alert| ... } ⇒ Object
Displays a UIAlertView.
-
.bounds ⇒ Object
Main Screen bounds.
-
.can_open_url(url) ⇒ Object
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.
-
.current_locale ⇒ NSLocale
Locale of user settings.
-
.delegate ⇒ Object
Application Delegate.
- .development? ⇒ Boolean
-
.documents_path ⇒ String
Returns the application's document directory path where users might be able to upload content.
-
.environment ⇒ Object
the current application environment : development, test, release.
-
.frame ⇒ Object
Return application frame.
- .identifier ⇒ Object
- .info_plist ⇒ Object
- .ios? ⇒ Boolean
- .name ⇒ Object
-
.notification_center ⇒ NSNotificationCenter
Returns the default notification center.
-
.open_url(url) ⇒ Object
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(“matt.aimonetti.net”) App.open_url(“fb://profile”).
- .osx? ⇒ Boolean
- .release? ⇒ Boolean
-
.resources_path ⇒ String
Returns the application resource path where resource located.
-
.run_after(delay, &block) ⇒ Object
Executes a block after a certain delay Usage example: App.run_after(0.5) { p “It's #Time.now” }.
-
.shared ⇒ Object
the Application object.
- .states ⇒ Object
- .test? ⇒ Boolean
- .user_cache ⇒ Object
- .version ⇒ Object
-
.window ⇒ Object
the Application Window.
- .windows ⇒ Object
Methods included from Deprecated
Class Method Details
.alert(title, *args) {|alert| ... } ⇒ Object
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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'motion/core/ios/app.rb', line 38 def alert(title, *args, &block) = { cancel_button_title: 'OK' } .merge!(args.pop) if args.last.is_a?(Hash) if args.size > 0 && args.first.is_a?(String) [:cancel_button_title] = args.shift end [:title] = title [:buttons] = [:cancel_button_title] [:cancel_button_index] = 0 # FIXME: alerts don't have "Cancel" buttons alert = UIAlertView.default() yield(alert) if block_given? alert.show alert end |
.bounds ⇒ Object
Main Screen bounds. Useful when starting the app
64 65 66 |
# File 'motion/core/ios/app.rb', line 64 def bounds UIScreen.mainScreen.bounds end |
.can_open_url(url) ⇒ Object
21 22 23 24 25 26 |
# 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 ⇒ NSLocale
Returns locale of user settings
66 67 68 69 70 71 72 73 |
# File 'motion/core/app.rb', line 66 def current_locale languages = NSLocale.preferredLanguages if languages.count > 0 return NSLocale.alloc.initWithLocaleIdentifier(languages.first) else return NSLocale.currentLocale end end |
.delegate ⇒ Object
Application Delegate
15 16 17 |
# File 'motion/core/osx/app.rb', line 15 def delegate shared.delegate end |
.development? ⇒ Boolean
80 81 82 |
# File 'motion/core/app.rb', line 80 def development? environment == 'development' end |
.documents_path ⇒ String
Returns the application's document directory path where users might be able to upload content.
11 12 13 |
# File 'motion/core/app.rb', line 11 def documents_path NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0] end |
.environment ⇒ Object
the current application environment : development, test, release
76 77 78 |
# File 'motion/core/app.rb', line 76 def environment RUBYMOTION_ENV end |
.frame ⇒ Object
Return application frame
59 60 61 |
# File 'motion/core/ios/app.rb', line 59 def frame UIScreen.mainScreen.applicationFrame end |
.identifier ⇒ Object
57 58 59 |
# File 'motion/core/app.rb', line 57 def identifier NSBundle.mainBundle.bundleIdentifier end |
.info_plist ⇒ Object
49 50 51 |
# File 'motion/core/app.rb', line 49 def info_plist NSBundle.mainBundle.infoDictionary end |
.ios? ⇒ Boolean
96 97 98 |
# File 'motion/core/app.rb', line 96 def ios? Kernel.const_defined?(:UIApplication) end |
.name ⇒ Object
53 54 55 |
# File 'motion/core/app.rb', line 53 def name info_plist['CFBundleDisplayName'] end |
.notification_center ⇒ NSNotificationCenter
Returns the default notification center
23 24 25 |
# File 'motion/core/app.rb', line 23 def notification_center NSNotificationCenter.defaultCenter end |
.open_url(url) ⇒ Object
9 10 11 12 |
# File 'motion/core/osx/app.rb', line 9 def open_url(url) url = NSURL.URLWithString(url) unless url.is_a?(NSURL) NSWorkspace.sharedWorkspace.openURL(url) end |
.osx? ⇒ Boolean
92 93 94 |
# File 'motion/core/app.rb', line 92 def osx? Kernel.const_defined?(:NSApplication) end |
.release? ⇒ Boolean
88 89 90 |
# File 'motion/core/app.rb', line 88 def release? environment == 'release' end |
.resources_path ⇒ String
Returns the application resource path where resource located
17 18 19 |
# File 'motion/core/app.rb', line 17 def resources_path NSBundle.mainBundle.resourcePath end |
.run_after(delay, &block) ⇒ Object
35 36 37 38 39 40 41 |
# 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 ⇒ Object
the Application object.
20 21 22 |
# File 'motion/core/osx/app.rb', line 20 def shared NSApplication.sharedApplication end |
.states ⇒ Object
45 46 47 |
# File 'motion/core/app.rb', line 45 def states @states end |
.test? ⇒ Boolean
84 85 86 |
# File 'motion/core/app.rb', line 84 def test? environment == 'test' end |
.user_cache ⇒ Object
27 28 29 |
# File 'motion/core/app.rb', line 27 def user_cache NSUserDefaults.standardUserDefaults end |
.version ⇒ Object
61 62 63 |
# File 'motion/core/app.rb', line 61 def version info_plist['CFBundleVersion'] end |
.window ⇒ Object
the Application Window
83 84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ Object
78 79 80 |
# File 'motion/core/ios/app.rb', line 78 def windows UIApplication.sharedApplication.windows end |