Posted By

sag333ar on 11/19/10


Tagged

iphone iOS4 MFMailComposeViewController iPhone30 iPad32


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sag333ar


MFMailComposeViewController with availability check iOS4 iPhone3.0 iPad3.2


 / Published in: Objective C
 

  1. -(void)sendMailByTitle:(BOOL)title andText:(NSString*)text byViewController:(UIViewController*)vCtr{
  2. self.strText=text;
  3. self.strTitle=title;
  4. vRef=vCtr;
  5. [self emailThisNote];
  6. }
  7.  
  8. -(void)emailThisNote{
  9. Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
  10. if (mailClass != nil) {
  11. // We must always check whether the current device is configured for sending emails
  12. if ([mailClass canSendMail]){
  13. [self displayComposerSheet];
  14. }else {
  15. [self launchMailAppOnDevice];
  16. }
  17. }else {
  18. [self launchMailAppOnDevice];
  19. }
  20. }
  21.  
  22.  
  23. #pragma mark -
  24. #pragma mark Compose Mail
  25.  
  26. // Displays an email composition interface inside the application. Populates all the Mail fields.
  27. -(void)displayComposerSheet {
  28. MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  29. picker.mailComposeDelegate = self;
  30.  
  31. // load value from DocDetail.plist
  32. NSDictionary *d=[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"DocDetail" ofType:@"plist"]];
  33.  
  34. [picker setSubject:[d valueForKey:@"DocTitle"]];
  35.  
  36.  
  37. NSString *strDocTitle=[d valueForKey:@"DocTitle"];
  38. NSString *strDtlTitle=(self.strTitle)?[d valueForKey:@"NoteText"]:[d valueForKey:@"HighlightText"];
  39.  
  40. NSString *strDocLink=[d valueForKey:@"DocumentLink"];
  41. NSString *strImgDocuApp=[d valueForKey:@"Image_zzzApp"];
  42. NSString *strImgzzzCompany=[d valueForKey:@"Image_zzzCompany"];
  43. NSString *strWebLink=[d valueForKey:@"Web_Link"];
  44. NSString *strEmailLink=[d valueForKey:@"Email_link"];
  45.  
  46.  
  47.  
  48. NSString *strToMail=[[NSString alloc] initWithFormat:@"<html><body><p><font family='Arial' size='3pt' color='darkblue'>%@</font></p><h3 style='color:brown'><u>%@</u></h3><p><font family='Arial' size='3pt' color='brown' style='background-color:yellow'>%@</font></p><p><font family='Arial' size='3pt' color='darkblue'>You can download this DocuApps&trade; document App for free by clicking this link:<a href='%@'>%@</a></font></p><p><font family='Arial' size='3pt' color='green' style='font-weight:bold'><img src='%@' height='88px' width='125px'><br>DocuApps&trade; is a product of The APP Company</font></p><img src='%@' width='175px' height='43px'><br><font family='Arial' style='font-weight:bold' color='blue'>For more information:</font><br><font family='Arial' size='3pt' color='brown'>Web :<a href='http://%@'>%@</a><br>Email: <a href='mailto:%@'>%@</a><br></font><font family='Century Gothic' size='1px' color='brown'>&copy;2010 The APP Company. All Rights Reserved.</font><hr></body></html>",strDtlTitle,strDocTitle,self.strText,strDocLink,strDocLink,strImgzzzApp,zzzCompanympany,strWebLink,strWebLink,strEmailLink,strEmailLink];
  49.  
  50. [picker setMessageBody:strToMail isHTML:YES];
  51. [strToMail release]; strToMail=nil;
  52.  
  53. [vRef presentModalViewController:picker animated:YES];
  54. [picker release];
  55. }
  56.  
  57.  
  58. // Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
  59. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
  60. [vRef dismissModalViewControllerAnimated:YES];
  61. }
  62.  
  63. #pragma mark -
  64. #pragma mark Workaround
  65.  
  66. // Launches the Mail application on the device.
  67. -(void)launchMailAppOnDevice {
  68. UIAlertView *av=[[[UIAlertView alloc] initWithTitle:@"Message" message:@"Mail composer not available." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
  69. [av show];
  70. }

Report this snippet  

You need to login to post a comment.