Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Email example #17

Merged
merged 1 commit into from

2 participants

@adelevie

Uses the MessageUI framework for easy in-app emailing.

Translated from http://stackoverflow.com/a/1513433/94154/.

@alloy alloy merged commit be391a7 into HipByte:master
@alloy
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 Email/.gitignore
@@ -0,0 +1,5 @@
+.repl_history
+build
+resources/*.nib
+resources/*.momd
+resources/*.storyboardc
View
26 Email/README.md
@@ -0,0 +1,26 @@
+# Email example
+
+An example of how to send email from within a RubyMotion app
+
+The code contains a basic translation of Objective-C code from http://stackoverflow.com/a/1513433/94154.
+
+Synopsis:
+
+From a `UIViewController`:
+
+```ruby
+def presentEmailEditor
+ controller = MFMailComposeViewController.alloc.init
+ controller.mailComposeDelegate = self
+ controller.setSubject("My Subject")
+ controller.setMessageBody("Hello there", isHTML:false)
+ self.presentModalViewController(controller, animated:true)
+end
+
+def mailComposeController(controller, didFinishWithResult:result, error:error)
+ if result == MFMailComposeResultSent
+ puts "It's away!"
+ end
+ self.dismissModalViewControllerAnimated(true)
+end
+```
View
9 Email/Rakefile
@@ -0,0 +1,9 @@
+$:.unshift("/Library/RubyMotion/lib")
+require 'motion/project'
+
+Motion::Project::App.setup do |app|
+ # Use `rake config' to see complete project settings.
+ app.name = 'Email'
+
+ app.frameworks += ['MessageUI']
+end
View
62 Email/app/app_delegate.rb
@@ -0,0 +1,62 @@
+class AppDelegate
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
+ @window.rootViewController = MainController.alloc.init
+ @window.rootViewController.wantsFullScreenLayout = true
+ @window.makeKeyAndVisible
+ true
+ end
+end
+
+class MainController < UIViewController
+ def viewDidLoad
+ #creating a button and setting its title
+ @button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
+ @button.setTitle('Send Email', forState:UIControlStateNormal)
+
+ #connects the presentEmailEditor method to the button-press action
+ @button.addTarget(self, action:'presentEmailEditor', forControlEvents:UIControlEventTouchUpInside)
+
+ #specifies the button location on the view
+ margin = 20
+ @button.frame = [[margin, 260], [view.frame.size.width - margin * 2, 40]]
+
+ #binds the button to the view
+ view.addSubview(@button)
+ end
+
+ def presentEmailEditor
+ # called when the button is pressed
+
+ # http://stackoverflow.com/a/1513433/94154
+ #
+ # MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
+ # controller.mailComposeDelegate = self;
+ # [controller setSubject:@"My Subject"];
+ # [controller setMessageBody:@"Hello there." isHTML:NO];
+ # if (controller) [self presentModalViewController:controller animated:YES];
+ # [controller release];
+
+ controller = MFMailComposeViewController.alloc.init
+ controller.mailComposeDelegate = self
+ controller.setSubject("My Subject")
+ controller.setMessageBody("Hello there", isHTML:false)
+ self.presentModalViewController(controller, animated:true)
+ end
+
+ #- (void)mailComposeController:(MFMailComposeViewController*)controller
+ # didFinishWithResult:(MFMailComposeResult)result
+ # error:(NSError*)error;
+ #{
+ # if (result == MFMailComposeResultSent) {
+ # NSLog(@"It's away!");
+ # }
+ # [self dismissModalViewControllerAnimated:YES];
+ #}
+ def mailComposeController(controller, didFinishWithResult:result, error:error)
+ if result == MFMailComposeResultSent
+ puts "It's away!"
+ end
+ self.dismissModalViewControllerAnimated(true)
+ end
+end
View
9 Email/spec/main_spec.rb
@@ -0,0 +1,9 @@
+describe "Application 'Email'" do
+ before do
+ @app = UIApplication.sharedApplication
+ end
+
+ it "has one window" do
+ @app.windows.size.should == 1
+ end
+end
Something went wrong with that request. Please try again.