Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.89 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Handling mail draft ( i.e. MFMailComposeResultSaved ) in MFMailComposeViewControllerDelegate
  2. -(void)showEmailComposer;
  3. -(void) displayComposerSheet;
  4.        
  5. -(void)showEmailComposer {
  6.  
  7.     NSLog(@"showEmailComposer: begin");
  8.  
  9. Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
  10. if (mailClass != nil)
  11. {
  12.     if ([mailClass canSendMail]) {
  13.         NSLog(@"showEmailComposer: Calling displayComposerSheet");
  14.         [self displayComposerSheet];
  15.  
  16.     }
  17. }
  18.  }
  19.  
  20.  
  21. #pragma mark -
  22. #pragma mark Compose Mail
  23.  
  24. -(void) displayComposerSheet {
  25. mailComposer = [[MFMailComposeViewController alloc] init];
  26. mailComposer.mailComposeDelegate = self;
  27. [self presentModalViewController:mailComposer animated:YES];
  28. }
  29.  
  30.  
  31. -(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
  32.  
  33. NSString *alertTitle;
  34. NSString *alertMsg;
  35.  
  36. // Notifies users on errors, if any
  37. switch (result) {
  38.  
  39.     case MFMailComposeResultCancelled:
  40.         alertTitle = @"Cancelled";
  41.         alertMsg = @"Mail composition got cancelled";
  42.         break;
  43.     case MFMailComposeResultSaved:
  44.         alertTitle = @"Success - Saved";
  45.         alertMsg = @"Mail got saved successfully!";
  46.         break;
  47.     case MFMailComposeResultSent:
  48.         alertTitle = @"Success - Sent";
  49.         alertMsg = @"Mail sent successfully!";
  50.         break;
  51.     case MFMailComposeResultFailed:
  52.         alertTitle = @"Failure";
  53.         alertMsg = @"Sending the mail failed";
  54.         break;
  55.     default:
  56.         alertTitle = @"Failure";
  57.         alertMsg = @"Mail could not be sent";
  58.         break;
  59. }
  60.  
  61. UIAlertView *alert = [[UIAlertView alloc]
  62.                       initWithTitle:alertTitle
  63.                       message:alertMsg
  64.                       delegate:nil
  65.                       cancelButtonTitle:@"OK"
  66.                       otherButtonTitles:nil];
  67. [alert show];
  68.  
  69. [self dismissModalViewControllerAnimated:YES];
  70. }