Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created November 13, 2012 05:50
Show Gist options
  • Save ChrisRisner/4064206 to your computer and use it in GitHub Desktop.
Save ChrisRisner/4064206 to your computer and use it in GitHub Desktop.
iOS Day 15
-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
switch (result)
{
case MFMailComposeResultSent:
//mail sent
break;
case MFMailComposeResultCancelled:
//mail cancelled
break;
case MFMailComposeResultSaved:
//draft saved
break;
case MFMailComposeResultFailed:
//failure
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)tappedMakePhoneCall:(id)sender {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:+18008008000"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:18008008000"]];
}
}
-(void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result) {
case MessageComposeResultCancelled:
//cancelled
break;
case MessageComposeResultFailed:
//failed
break;
case MessageComposeResultSent:
//sent
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MessageUI/MFMessageComposeViewController.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>
- (IBAction)tappedSendSMS:(id)sender {
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageComposer = [[MFMessageComposeViewController alloc] init];
messageComposer.body = @"this is the body";
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
}
}
- (IBAction)tappedOpenSafar:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.windowsazure.com"]];
}
- (IBAction)tappedSendEmail:(id)sender {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setSubject:@"The Email Subject"];
[mailComposer setMessageBody:@"The email body." isHTML:NO];
mailComposer.mailComposeDelegate = self;
[self presentViewController:mailComposer animated:YES completion:nil];
}
- (IBAction)tappedSendTweet:(id)sender {
SLComposeViewController *socialComposerSheet;
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
socialComposerSheet = [[SLComposeViewController alloc] init];
socialComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[socialComposerSheet setInitialText:[NSString stringWithFormat:@"My Tweet!",socialComposerSheet.serviceType]];
[self presentViewController:socialComposerSheet animated:YES completion:nil];
}
[socialComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultDone:
//post worked
break;
case SLComposeViewControllerResultCancelled:
//cancelled
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
}
@interface ViewController : UIViewController
- (IBAction)tappedSendEmail:(id)sender;
- (IBAction)tappedSendSMS:(id)sender;
- (IBAction)tappedOpenSafar:(id)sender;
- (IBAction)tappedMakePhoneCall:(id)sender;
- (IBAction)tappedSendTweet:(id)sender;
- (IBAction)tappedSendFacebook:(id)sender;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment