Module: BubbleWrap::App
- Defined in:
- motion/core/app.rb
Class Method Summary collapse
-
.alert(title, *args) {|alert| ... } ⇒ Object
Displays a UIAlertView.
-
.bounds ⇒ Object
Main Screen bounds.
-
.current_locale ⇒ NSLocale
Locale of user settings.
-
.delegate ⇒ Object
Application Delegate.
-
.documents_path ⇒ String
Returns the application’s document directory path where users might be able to upload content.
-
.frame ⇒ Object
Return application frame.
- .identifier ⇒ Object
- .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.
-
.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
- .user_cache ⇒ Object
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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'motion/core/app.rb', line 37 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 alert = UIAlertView.alloc.initWithTitle title, message: [:message], delegate: nil, cancelButtonTitle: [:cancel_button_title], otherButtonTitles: nil yield(alert) if block_given? alert.show alert end |
.bounds ⇒ Object
Main Screen bounds. Useful when starting the app
99 100 101 |
# File 'motion/core/app.rb', line 99 def bounds UIScreen.mainScreen.bounds end |
.current_locale ⇒ NSLocale
Returns locale of user settings.
114 115 116 117 118 119 120 121 |
# File 'motion/core/app.rb', line 114 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
104 105 106 |
# File 'motion/core/app.rb', line 104 def delegate UIApplication.sharedApplication.delegate end |
.documents_path ⇒ String
Returns the application’s document directory path where users might be able to upload content.
9 10 11 |
# File 'motion/core/app.rb', line 9 def documents_path NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0] end |
.frame ⇒ Object
Return application frame
94 95 96 |
# File 'motion/core/app.rb', line 94 def frame UIScreen.mainScreen.applicationFrame end |
.identifier ⇒ Object
89 90 91 |
# File 'motion/core/app.rb', line 89 def identifier NSBundle.mainBundle.bundleIdentifier end |
.name ⇒ Object
85 86 87 |
# File 'motion/core/app.rb', line 85 def name NSBundle.mainBundle.objectForInfoDictionaryKey 'CFBundleDisplayName' end |
.notification_center ⇒ NSNotificationCenter
Returns the default notification center
21 22 23 |
# File 'motion/core/app.rb', line 21 def notification_center NSNotificationCenter.defaultCenter end |
.open_url(url) ⇒ Object
Opens an url (string or instance of ‘NSURL`) in the device’s web browser. Usage Example:
App.open_url("http://matt.aimonetti.net")
72 73 74 75 76 77 |
# File 'motion/core/app.rb', line 72 def open_url(url) unless url.is_a?(NSURL) url = NSURL.URLWithString(url) end UIApplication.sharedApplication.openURL(url) end |
.resources_path ⇒ String
Returns the application resource path where resource located
15 16 17 |
# File 'motion/core/app.rb', line 15 def resources_path NSBundle.mainBundle.resourcePath end |
.run_after(delay, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'motion/core/app.rb', line 60 def run_after(delay,&block) NSTimer.scheduledTimerWithTimeInterval( delay, target: block, selector: "call:", userInfo: nil, repeats: false) end |
.shared ⇒ Object
the Application object.
109 110 111 |
# File 'motion/core/app.rb', line 109 def shared UIApplication.sharedApplication end |
.states ⇒ Object
81 82 83 |
# File 'motion/core/app.rb', line 81 def states @states end |
.user_cache ⇒ Object
25 26 27 |
# File 'motion/core/app.rb', line 25 def user_cache NSUserDefaults.standardUserDefaults end |