Module: BubbleWrap::Mail
- Defined in:
- motion/mail/mail.rb,
motion/mail/result.rb
Defined Under Namespace
Classes: Result
Class Method Summary collapse
- .can_send_mail? ⇒ Boolean
-
.compose(options = {}, &callback) ⇒ Object
Base method to create your in-app mail ————————————— EX BW::Mail.compose( delegate: self, # optional, will use root view controller by default to: [ “[email protected]” ], cc: [ “[email protected]”, “[email protected]” ], bcc: [ “[email protected]” ], html: false, subject: “My Subject”, message: “This is my message. It isn’t very long.”, animated: false ) do |result, error| result.sent? # => boolean result.canceled? # => boolean result.saved? # => boolean result.failed? # => boolean error # => NSError end.
- .create_mail_controller(options = {}) ⇒ Object
-
.mailComposeController(controller, didFinishWithResult: result, error: error) ⇒ Object
Event when the MFMailComposeViewController is closed ————————————————————- the callback is fired if it was present in the constructor.
Class Method Details
.can_send_mail? ⇒ Boolean
65 66 67 |
# File 'motion/mail/mail.rb', line 65 def can_send_mail? !!MFMailComposeViewController.canSendMail end |
.compose(options = {}, &callback) ⇒ Object
Base method to create your in-app mail
EX
BW::Mail.compose(
delegate: self, # optional, will use root view controller by default
to: [ "[email protected]" ],
cc: [ "[email protected]", "[email protected]" ],
bcc: [ "[email protected]" ],
html: false,
subject: "My Subject",
message: "This is my message. It isn't very long.",
animated: false
) do |result, error|
result.sent? # => boolean
result.canceled? # => boolean
result.saved? # => boolean
result.failed? # => boolean
error # => NSError
end
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'motion/mail/mail.rb', line 25 def compose( = {}, &callback) = { delegate: App.window.rootViewController, animated: true, html: false, to: [], cc: [], bcc: [], subject: 'Contact' }.merge() @delegate = [:delegate] @mailer_is_animated = [:animated] @callback = callback @callback.weak! if @callback && BubbleWrap.use_weak_callbacks? @mail_controller = create_mail_controller() @delegate.presentViewController(@mail_controller, animated: @mailer_is_animated, completion: [:completion]) end |
.create_mail_controller(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'motion/mail/mail.rb', line 46 def create_mail_controller( = {}) unless can_send_mail? controller = UIAlertController.alertControllerWithTitle("Email", message:"Cannot compose an email. Please run on device.", preferredStyle:UIAlertControllerStyleAlert) controller.addAction(UIAlertAction.actionWithTitle:"OK",style:UIAlertActionStyleDefault, handler:@callback) return controller end mail_controller = MFMailComposeViewController.alloc.init mail_controller.mailComposeDelegate = self mail_controller.setToRecipients(Array([:to])) mail_controller.setCcRecipients(Array([:cc])) mail_controller.setBccRecipients(Array([:bcc])) mail_controller.setSubject([:subject]) mail_controller.setMessageBody([:message], isHTML: !![:html]) mail_controller end |
.mailComposeController(controller, didFinishWithResult: result, error: error) ⇒ Object
Event when the MFMailComposeViewController is closed
the callback is fired if it was present in the constructor
73 74 75 76 |
# File 'motion/mail/mail.rb', line 73 def mailComposeController(controller, didFinishWithResult: result, error: error) @delegate.dismissModalViewControllerAnimated(@mailer_is_animated) @callback.call Result.new(result, error) if @callback end |