2011-06-22 9 views

答えて

-4

読むSending mail with MFMailComposeViewController

まずMessageUIフレームワークが含まAN MFMailComposeViewControllerDelegateを実装します。

#import <MessageUI/MessageUI.h> 
#import <MessageUI/MFMailComposeViewController.h> 

@interface MainViewController : UIViewController <MFMailComposeViewControllerDelegate> { 
} 

次に、メールコントローラを削除するためのデリゲートメソッドを実装します。

- (IBAction)pressentMailController:(id)sender { 

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Test subject!"]; 

    // Set up the recipients. 
    /*NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", 
          nil]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", 
          @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", 
           nil]; 

    [picker setToRecipients:toRecipients]; 
    [picker setCcRecipients:ccRecipients]; 
    [picker setBccRecipients:bccRecipients]; 
    */ 

    // Attach an image to the email. 
    /*NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano" 
                ofType:@"png"]; 
    NSData *myData = [NSData dataWithContentsOfFile:path]; 
    [picker addAttachmentData:myData mimeType:@"image/png" 
        fileName:@"ipodnano"]; 
    */ 
    // Fill out the email body text. 
    NSString *emailBody = @"It is raining in sunny California!"; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    // Present the mail composition interface. 
    [self presentModalViewController:picker animated:YES]; 
    [picker release]; // Can safely release the controller now. 
} 

// The mail compose view controller delegate method 
- (void)mailComposeController:(MFMailComposeViewController *)controller 
      didFinishWithResult:(MFMailComposeResult)result 
         error:(NSError *)error 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

コードでは、受信者、本文、件名、添付ファイルを追加できます。必要に応じて行のコメントを外します。送信

enter image description here

+0

あなたの答えのためのおかげで、しかし、あなたは違った私の質問を理解し、私は意味:テストする方法MFMailComposeViewControllerが本当に送信ボタンを押した後、電子メールかを送ったかどうか!!?電子メールをチェックアウトしたときに、そのコンポーザーから(シミュレータを使用して)送信された電子メールを見つけることができなかったので、間違った質問に答えることができます。 – JaHelia

+1

-1疑問は、シミュレータでメールコントローラをテストする方法でした。答えは、コードを書く方法を示していますが、メールコントローラがシミュレータで動作しないため、テストを許可しません。 – Lee

1

実際のメールは、シミュレータから可能ではありません。 APPを電話機にインストールしてテストします。

しかし、あなたのAPPが行うことができます/制御する/シミュレータで指定することができます。 [送信]ボタンを押した後のすべてがAppleであるため、 が正常に機能しているとみなすことができます。

4

ありませんあなたは我々は次のように限られたものをテストすることができます(私はあなたのメールが配信されないという意味で)...シミュレータ上でそれをテストすることはできません:ビューがものになるかどうか、何をするとき、ユーザーがクリック起こりますキャンセルボタンなど...

メールが配信されたかどうかをテストするには、デバイスを使用する必要があります。あなたの設定には何らかのメール(例:gmail)が設定されている必要があります。

関連する問題