Module: BubbleWrap::SMS

Defined in:
motion/sms/sms.rb,
motion/sms/result.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.can_send_sms?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'motion/sms/sms.rb', line 40

def can_send_sms?
  !!MFMessageComposeViewController.canSendText
end

.compose(options = {}, &callback) ⇒ Object

Base method to create your in-app mail


EX BW::SMS.compose (

delegate: self, # optional, will use root view controller by default
to: [ "1(234)567-8910" ],
message: "This is my message. It isn't very long.",
animated: false

) {|result, error|

result.sent?      # => boolean
result.canceled?  # => boolean
result.failed?    # => boolean
error             # => NSError
}


22
23
24
25
26
27
28
29
30
# File 'motion/sms/sms.rb', line 22

def compose(options = {}, &callback)
  @delegate = options[:delegate] || App.window.rootViewController
  @callback = callback
  @callback.weak! if @callback && BubbleWrap.use_weak_callbacks?

  @message_controller = create_message_controller(options)
  @message_is_animated = options[:animated] == false ? false : true
  @delegate.presentModalViewController(@message_controller, animated: @message_is_animated)
end

.create_message_controller(options = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'motion/sms/sms.rb', line 32

def create_message_controller(options = {})
  message_controller = MFMessageComposeViewController.alloc.init
  message_controller.messageComposeDelegate = self
  message_controller.body = options[:message]
  message_controller.recipients = Array(options[:to])
  message_controller
end

.messageComposeViewController(controller, didFinishWithResult: result) ⇒ Object

Event when the MFMessageComposeViewController is closed


the callback is fired if it was present in the constructor



48
49
50
51
# File 'motion/sms/sms.rb', line 48

def messageComposeViewController(controller, didFinishWithResult: result)
  @delegate.dismissModalViewControllerAnimated(@message_is_animated)
  @callback.call Result.new(result) if @callback
end