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)

Methods included from Deprecated

#deprecated, included

Class Method Details

+ (Object) alert(title, *args) {|alert| ... }

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

Yields:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'motion/core/ios/app.rb', line 26

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

+ (Object) bounds

Main Screen bounds. Useful when starting the app



52
53
54
# File 'motion/core/ios/app.rb', line 52

def bounds
  UIScreen.mainScreen.bounds
end

+ (NSLocale) current_locale



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

+ (Object) delegate

Application Delegate



6
7
8
# File 'motion/core/osx/app.rb', line 6

def delegate
  shared.delegate
end

+ (Boolean) development?



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

def development?
  environment == 'development'
end

+ (String) documents_path

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

+ (Object) environment

the current application environment : development, test, release



76
77
78
# File 'motion/core/app.rb', line 76

def environment
  RUBYMOTION_ENV
end

+ (Object) frame

Return application frame



47
48
49
# File 'motion/core/ios/app.rb', line 47

def frame
  UIScreen.mainScreen.applicationFrame
end

+ (Object) identifier



57
58
59
# File 'motion/core/app.rb', line 57

def identifier
  NSBundle.mainBundle.bundleIdentifier
end

+ (Object) info_plist



49
50
51
# File 'motion/core/app.rb', line 49

def info_plist
  NSBundle.mainBundle.infoDictionary
end

+ (Boolean) ios?



96
97
98
# File 'motion/core/app.rb', line 96

def ios?
  Kernel.const_defined?(:UIApplication)
end

+ (Object) name



53
54
55
# File 'motion/core/app.rb', line 53

def name
  info_plist['CFBundleDisplayName']
end

+ (NSNotificationCenter) notification_center

Returns the default notification center



23
24
25
# File 'motion/core/app.rb', line 23

def notification_center
  NSNotificationCenter.defaultCenter
end

+ (Object) open_url(url)

Opens an url (string or instance of `NSURL`) in the device's web browser. Usage Example:

App.open_url("http://matt.aimonetti.net")


9
10
11
12
13
14
# File 'motion/core/ios/app.rb', line 9

def open_url(url)
  unless url.is_a?(NSURL)
    url = NSURL.URLWithString(url)
  end
  UIApplication.sharedApplication.openURL(url)
end

+ (Boolean) osx?



92
93
94
# File 'motion/core/app.rb', line 92

def osx?
  Kernel.const_defined?(:NSApplication)
end

+ (Boolean) release?



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

def release?
  environment == 'release'
end

+ (String) resources_path

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

+ (Object) run_after(delay, &block)

Executes a block after a certain delay Usage example:

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


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

+ (Object) shared

the Application object.



11
12
13
# File 'motion/core/osx/app.rb', line 11

def shared
  NSApplication.sharedApplication
end

+ (Object) states



45
46
47
# File 'motion/core/app.rb', line 45

def states
  @states
end

+ (Boolean) test?



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

def test?
  environment == 'test'
end

+ (Object) user_cache



27
28
29
# File 'motion/core/app.rb', line 27

def user_cache
  NSUserDefaults.standardUserDefaults
end

+ (Object) version



61
62
63
# File 'motion/core/app.rb', line 61

def version
  info_plist['CFBundleVersion']
end

+ (Object) window

the Application Window



71
72
73
74
75
76
77
78
79
80
81
# File 'motion/core/ios/app.rb', line 71

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

+ (Object) windows



66
67
68
# File 'motion/core/ios/app.rb', line 66

def windows
  UIApplication.sharedApplication.windows
end