2013-06-25 20 views
5

私はxcodeを初めて使い、アプリケーションで電子メールを送信する方法が不思議です!私のコードは下ですが、エラーが表示される "jakem 'の表示されない@interfaceはセレクタ' presentViewControllerAnimated: 'を宣言しています。私のコードは完全に間違っていますか?またはセレクタを宣言するのを忘れてしまったのですが、セレクタを宣言するにはどうすればいいですか?私は少なくとも1時間インターネット上で研究してきましたが、何も動いていません。誰か助けてください!Xcodeでアプリ内の電子メールを送信する方法は?

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

を私はSendgridのために働くXcodeでアプリの内部で電子メールを送信するには、ここから

Send email from iOS app using SendGrid

+0

これを読んでみてくださいhttp://stackoverflow.com/help/deleted-answers、**理解していない**答えを理解する。すなわち、「根本的に質問に答えない回答」:**外部サイトへのリンク以上のもの** –

-1

をコードを使用してください。 Objective-cライブラリを使用して、アプリ内から電子メールを迅速に送信できます(https://github.com/sendgrid/sendgrid-objc)。ココアポダイを使用すると、プロジェクトにライブラリをすばやくインストールできます。

は、次のようになり、あなたの(IBAction)からの電子メールを送信する:.Hヘッダーファイル内

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

を.M実装ファイルに.... 。

- (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]; 
} 
関連する問題