Guest User

Untitled

a guest
Oct 28th, 2017
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //************************---------------------------Mail Code Start------------------************************************************//
  2.  
  3.  
  4.  
  5. -(IBAction)showPicker:(id)Sender
  6.  
  7. {
  8.     Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
  9.    
  10.     if (mailClass != nil)
  11.        
  12.     {
  13.        
  14.         // We must always check whether the current device is configured for sending emails
  15.        
  16.         if ([mailClass canSendMail])
  17.            
  18.         {
  19.            
  20.             [self displayComposerSheet];
  21.            
  22.         }
  23.        
  24.         else
  25.            
  26.         {
  27.            
  28.             [self launchMailAppOnDevice];
  29.            
  30.         }
  31.        
  32.     }
  33.    
  34.     else
  35.        
  36.     {
  37.        
  38.         [self launchMailAppOnDevice];
  39.        
  40.     }
  41.    
  42. }
  43.  
  44.  
  45.  
  46.      //---------------------------------------------------------------------------/////
  47. -(void)displayComposerSheet
  48.  
  49. {
  50.    
  51.     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  52.    
  53.     picker.mailComposeDelegate = self;
  54.    
  55.    
  56.    
  57.     [picker setSubject:am.mailtitle];
  58.    
  59.    
  60.    
  61.    
  62.    
  63.     // Set up recipients
  64.    
  65.     NSArray *toRecipients = [NSArray arrayWithObject:@"abc@gmail.com"];
  66.    
  67.     NSArray *ccRecipients = [NSArray arrayWithObjects:@"abc@yahoo.com", nil];
  68.    
  69.     NSArray *bccRecipients = [NSArray arrayWithObject:@"abc@gmail.com"];
  70.    
  71.    
  72.    
  73.     [picker setToRecipients:toRecipients];
  74.    
  75.     [picker setCcRecipients:ccRecipients];  
  76.    
  77.     [picker setBccRecipients:bccRecipients];
  78.    
  79.     NSString *emailBody = am.mailtext;
  80.    
  81.     [picker setMessageBody:emailBody isHTML:YES];
  82.    
  83.    
  84.    
  85.     [self presentModalViewController:picker animated:YES];
  86.    
  87.     [picker release];
  88.    
  89. }
  90.  
  91.  
  92. //---------------------------------------------------------------------------/////
  93.  
  94.  
  95. -(void)pushAlertCancel
  96. {
  97.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Canceled!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  98.     [alert show];
  99.     [alert release];
  100. }
  101.  
  102.  
  103. -(void)pushAlertSent
  104. {
  105.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Sent!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  106.     [alert show];
  107.     [alert release];
  108. }
  109.  
  110. -(void)pushAlertSaved
  111. {
  112.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Saved To Drafts!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  113.     [alert show];
  114.     [alert release];
  115. }
  116.  
  117.  
  118. -(void)pushAlertNotSent
  119. {
  120.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Not Sent!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  121.     [alert show];
  122.     [alert release];
  123. }
  124.  
  125. -(void)pushAlertFailed
  126. {
  127.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Mail Failed!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  128.     [alert show];
  129.     [alert release];
  130. }
  131.  
  132.  
  133.  
  134.  
  135. //---------------------------------------------------------------------------/////
  136.  
  137. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
  138.  
  139. {  
  140.    
  141.     // message.hidden = NO;
  142.     message.text=@"hello";
  143.    
  144.     // Notifies users about errors associated with the interface
  145.    
  146.    
  147.     switch (result)
  148.    
  149.     {
  150.            
  151.         case MFMailComposeResultCancelled:
  152.            
  153.             [self pushAlertCancel];         //message.text = @"Result: canceled";
  154.            
  155.             break;
  156.            
  157.         case MFMailComposeResultSaved:
  158.            
  159.             //message.text = @"Result: saved";
  160.             [self pushAlertSaved];  
  161.             break;
  162.            
  163.         case MFMailComposeResultSent:
  164.            
  165.             // message.text = @"Result: sent";
  166.             [self pushAlertSent];
  167.            
  168.             break;
  169.            
  170.         case MFMailComposeResultFailed:
  171.            
  172.             // message.text = @"Result: failed";
  173.             [self pushAlertFailed];
  174.            
  175.             break;
  176.            
  177.         default:
  178.            
  179.             // message.text = @"Result: not sent";
  180.             [self pushAlertNotSent];
  181.            
  182.             break;
  183.            
  184.     }
  185.    
  186.     [self dismissModalViewControllerAnimated:YES];
  187.    
  188. }
  189.  
  190.  
  191. //---------------------------------------------------------------------------/////
  192.  
  193. -(void)launchMailAppOnDevice
  194.  
  195. {
  196.    
  197.     NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
  198.    
  199.     NSString *body = @"&body=It is raining in sunny California!";
  200.    
  201.    
  202.    
  203.     NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
  204.    
  205.     email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  206.    
  207.    
  208.    
  209.     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
  210.    
  211. }
  212.  
  213.  
  214. //---------------------------------------------------------------------------/////
  215.  
  216.  
  217.  
  218.  
  219.  
  220. //**********************---------------------Mail Code Finish------------------****************************//
Add Comment
Please, Sign In to add comment