Module: BubbleWrap::App

Defined in:
motion/core/app.rb

Class Method Summary collapse

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.

Yields:



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)
  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

  alert = UIAlertView.alloc.initWithTitle title,
    message: options[:message],
    delegate: nil,
    cancelButtonTitle: options[:cancel_button_title],
    otherButtonTitles: nil

  yield(alert) if block_given?

  alert.show
  alert
end

.boundsObject

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_localeNSLocale

Returns locale of user settings.

Returns:

  • (NSLocale)

    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

.delegateObject

Application Delegate



104
105
106
# File 'motion/core/app.rb', line 104

def delegate
  UIApplication.sharedApplication.delegate
end

.documents_pathString

Returns the application’s document directory path where users might be able to upload content.

Returns:

  • (String)

    the path to the document directory



9
10
11
# File 'motion/core/app.rb', line 9

def documents_path
  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
end

.frameObject

Return application frame



94
95
96
# File 'motion/core/app.rb', line 94

def frame
  UIScreen.mainScreen.applicationFrame
end

.identifierObject



89
90
91
# File 'motion/core/app.rb', line 89

def identifier
  NSBundle.mainBundle.bundleIdentifier
end

.nameObject



85
86
87
# File 'motion/core/app.rb', line 85

def name
  NSBundle.mainBundle.objectForInfoDictionaryKey 'CFBundleDisplayName'
end

.notification_centerNSNotificationCenter

Returns the default notification center

Returns:



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_pathString

Returns the application resource path where resource located

Returns:

  • (String)

    the application main bundle resource path



15
16
17
# File 'motion/core/app.rb', line 15

def resources_path
  NSBundle.mainBundle.resourcePath
end

.run_after(delay, &block) ⇒ Object

Executes a block after a certain delay Usage example:

App.run_after(0.5) {  p "It's #{Time.now}"   }


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

.sharedObject

the Application object.



109
110
111
# File 'motion/core/app.rb', line 109

def shared
  UIApplication.sharedApplication
end

.statesObject



81
82
83
# File 'motion/core/app.rb', line 81

def states
  @states
end

.user_cacheObject



25
26
27
# File 'motion/core/app.rb', line 25

def user_cache
  NSUserDefaults.standardUserDefaults
end