2013-06-25 10 views
5

मैं एक्सकोड में नया हूं, और सोच रहा हूं कि ऐप में ईमेल कैसे भेजना है! मेरा कोड नीचे है, लेकिन मुझे त्रुटि मिल रही है "'jakem' के लिए कोई दृश्य @interface 'selectViewControllerAnimated:'" घोषित करता है। क्या मेरा कोड पूरी तरह से गलत है? या क्या मैं सिर्फ चयनकर्ता घोषित करना भूल गया, और मैं चयनकर्ता को कैसे घोषित करूं? मैंने कम से कम एक घंटे के लिए पूरे इंटरनेट पर शोध किया है, और कुछ भी काम नहीं कर रहा है। कृपया मेरी मदद करो!एक्सकोड में किसी ऐप के अंदर ई-मेल कैसे भेजें?

-(IBAction)sendEmail{ 

    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
    [composer setMailComposeDelegate:self]; 
    if ([MFMailComposeViewController canSendMail]) { 
    [composer setToRecipients:[NSArray   arrayWithObjects:@"[email protected]", nil]]; 
    [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
    [self presentViewController:composer animated:YES]; 

    } 

    } 

    -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 
    if(error) { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@", [error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil]; 
    [alert show]; 
    [self dismissViewControllerAnimated:YES]; 
    } 
    else { 
    [self dismissViewControllerAnimated:YES]; 
    } 
    } 

उत्तर

0

चेक, अगर आप MFMailComposeViewControllerDelegate हैं। आप

@interface YouClassName : UIViewController <MFMailComposeViewControllerDelegate> 

@end 
+0

प्रतिक्रिया के लिए धन्यवाद! और हाँ मैंने अपने हेडर फ़ाइल –

0

की तरह यह कर मैं तुम्हें गलत विधि का उपयोग कर रहे है।

[self presentViewController:(UIViewController *) animated:(BOOL) completion:(void)completion]; 
बजाय

का प्रयास करें:

[self presentViewController:composer animated:YES]; 
0
+0

में ऐसा किया है, कृपया यह जानने के लिए कि यह ** ** ** उत्तर नहीं है, इस http://stackoverflow.com/help/deleted-answers को पढ़ने का प्रयास करें। अर्थात्: "उत्तर जो मौलिक रूप से प्रश्न का उत्तर नहीं देते हैं": ** किसी बाहरी साइट के लिंक से मुश्किल से अधिक ** –

-1

मैं Sendgrid के लिए काम में एक ऐप्लिकेशन के अंदर ईमेल भेजने के लिए यहां से कोड का उपयोग करें। हमारे पास एक उद्देश्य-सी लाइब्रेरी है जो आपको अपने ऐप के अंदर से ईमेल भेजने की सुविधा देती है, https://github.com/sendgrid/sendgrid-objc। आप अपनी परियोजना में लाइब्रेरी को जल्दी से स्थापित करने के लिए कोकोपोड का उपयोग कर सकते हैं। .m कार्यान्वयन फ़ाइल में

-(IBAction)sendEmail{ 

sendgrid *msg = [sendgrid user:@"username" andPass:@"password"]; 
msg.to = @"[email protected]"; 
msg.from = @"[email protected]"; 
msg.text = @"hello world"; 
msg.html = @"<h1>hello world!</h1>"; 

[msg sendWithWeb]; 

} 
7
ज हेडर फाइल में

....

#import <UIKit/UIKit.h> 


#import <MessageUI/MessageUI.h> 



@interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate 
- (IBAction)showEmail:(id)sender; 



@end 

....:

फिर अपने (IBAction) से ईमेल भेजने इस प्रकार दिखाई देगा

- (IBAction)showEmail:(id)sender { 
// Email Subject 
NSString *emailTitle = @"Test Email"; 
// Email Content 
NSString *messageBody = @"iOS programming is so fun!"; 
// To address 
NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"]; 

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
mc.mailComposeDelegate = self; 
[mc setSubject:emailTitle]; 
[mc setMessageBody:messageBody isHTML:NO]; 
[mc setToRecipients:toRecipents]; 

// Present mail view controller on screen 
[self presentViewController:mc animated:YES completion:NULL]; 
} 




- (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; 
} 


// Close the Mail Interface 
[self dismissViewControllerAnimated:YES completion:NULL]; 
} 
संबंधित मुद्दे