2012-01-30 25 views
8

के साथ ToRecipients कैसे सेट करें मैं ईमेल प्राप्त करने का प्रयास कर रहा हूं जिसे मैं एक ईमेल भेजने के लिए चुनता हूं। लेकिन मुझे नहीं पता कि कैसे सेट करने के लिए जो उपयोगकर्ता हैं जिन्हें मैंने MFMailComposeViewController व्यू में चुना है।MFMailComposeViewController

if ([MFMailComposeViewController canSendMail]) 
    { 
     mailer = [[MFMailComposeViewController alloc] init]; 

     mailer.mailComposeDelegate = self; 
     [mailer setSubject:@"A Message from blablabl"]; 

     NSMutableArray *usersTo = [[NSMutableArray alloc] init]; 
     toRecipients = usersTo; 
     [mailer setToRecipients:toRecipients]; 

     NSString *emailBody = @"blablablabal"; 

     [mailer setMessageBody:emailBody isHTML:YES]; 

     // only for iPad 
     // mailer.modalPresentationStyle = UIModalPresentationPageSheet; 

     [self presentModalViewController:mailer animated:YES]; 
    } 
    else 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                 message:@"Your device doesn't support the composer sheet" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles: nil]; 
     [alert show]; 
    } 

प्रतिनिधि http://pastie.org/3281814

उत्तर

27

कुछ बातें यहाँ गलत हैं।

1)

MFMailComposeViewController के setToRecipients विधि प्राप्तकर्ताओं के साथ अपरिवर्तनीय सरणी पहले से ही सेट की उम्मीद है।

2)

और तुम एक खाली परिवर्तनशील सरणी करने के लिए इसे स्थापित कर रहे हैं। इस तरह

कोशिश कुछ:

NSArray *usersTo = [NSArray arrayWithObject: @"[email protected]"]; 
[mailer setToRecipients:usersTo]; 

और तुम यह काम देखना चाहिए।

+0

यह काम नहीं करता है .... "[email protected] और 1 अधिक \ U2026" क्योंकि के बाद वह डाल और एन, केवल एक ईमेल प्राप्त कर सकते हैं उन ... मैं uitextfield – user1177647

+0

@Michael Dautermann का आकार बदलने का प्रयास करने के लिए आईओएस सिम्युलेटर के साथ एक्सकोड में ऐप का परीक्षण करते समय ईमेल भेजने का कोई तरीका नहीं है क्योंकि मेल ऐप आईओएस सिम्युलेटर में सेटिंग्स से गायब है। जब मैं अपने मैक पर एक आईफोन डिवाइस कनेक्ट करता हूं, और इस डिवाइस पर एक्सकोड से ऐप चलाता हूं, तो मैक पर अपने आईफोन की स्क्रीन प्रदर्शित करने का कोई तरीका है ताकि मैं भौतिक डिवाइस पर चल रहे ऐप को नियंत्रित कर सकूं माउस और आईफोन डिवाइस पर स्क्रीन को छूने के बजाय मैक पर दिखाए गए स्क्रीन से ईमेल भेजें? बहुत धन्यवाद – bibscy

0
MFMailComposer In “ Swift “ and “ Objective c “ 
********************************************* 
In objective c 
Steps: 
1. Create new project. 
2. Add a button into storyboard. 
3. In .h add header file like “Import <MessageUI/MessageUI.h>” 
4. Add delegate to ViewController “ MFMailComposeViewControllerDelegate” 

5. In Button Action  { 
          NSString *emailTitle = “” 
          NSString *messageBody = “” 
          NSArray *toRecipents = “”         
          MFMailComposeViewController *VC = [[MFMailComposeViewController]alloc init]; 
          VC.mailComposeDelegate = self; 
          [VC.setSubject: emailTitle]; 
          [VC.setMessageBody: messageBody]; 
          [VC.setToRecepents: toRecipents]; 
      if([MFMailComposeViewController canSendMail]) { 
       [self presentViewController:mc animated:YES completion:NULL]; 
      } 

6.MailComposeController Function 

     - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail sent"); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail sent failure: %@", [error localizedDescription]); 
      break; 
     default: 
      break; 
    } 
    [self dismissViewControllerAnimated:YES completion:NULL]; 
} 

7. And also add FrameWork: MessageUI.FrameWork 

8. Run the App into mobile or Simulator.  




In Swift: 
******* 
Steps: 
1. Create New Project 

2. Add a button Storyboard 

3. In ViewController.Swift Class File Import MessageUI 

4. In Button Action ConfiguredMailComposer below Steps 
     { 
     let mailComposeViewController = configuredMailComposeViewController() 

     if MFMailComposeViewController.canSendMail() 
{ 
      self.present(mailComposeViewController, animated: true, completion: nil) 
      self.showSendmailSuccesfulAlert() 
     } else { 

      self.showSendMailErrorAlert() 

     } 
5. Implement the configure mail composer 

     func configuredMailComposeViewController() -> MFMailComposeViewController { 

     let mailComposerVC = MFMailComposeViewController() 
     mailComposerVC.mailComposeDelegate = self 
     mailComposerVC.setToRecipients(["[email protected]"]) 
     mailComposerVC.setSubject("Sending you an in-app e-mail...") 
     mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false) 
     return mailComposerVC 

    } 

6. MailComposer optional method 

     func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { 

     controller.dismiss(animated: true, completion: nil) 

    } 

7. After completed the step no: run the app into device or simulator.