3

アクションシートのボタンが呼び出されたときに呼び出される次のコードがあります。しかし、私がキャンセルを押してからドラフトを削除すると、それはただ料金を徴収し、却下しません。私は自分のアプリのどこかで同じコードを使用し、それをテーブルビューのセルから選択して呼び出すことができます。それがなぜここで働いていないのでしょうか?MFMailComposeViewControllerが表示から消滅しない

また、コンソールがフリーズしても、エラーメッセージは表示されません。あなたは、デリゲートメソッドを実装する必要があり

if([MFMailComposeViewController canSendMail]) 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Dr. Chrono Support"]; 

    NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary]; 
    NSString* versionNum = [infoDict objectForKey:@"CFBundleVersion"]; 
    NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"]; 
    NSString *text = [NSString stringWithFormat:@"%@ %@",appName,versionNum]; 

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

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

    // Attach an image to the email 
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"]; 
    //NSData *myData = [NSData dataWithContentsOfFile:path]; 
    //[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"]; 

    // Fill out the email body text 
    NSString *emailBody = text; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 

答えて

11

:このデリゲートメソッドに続いて

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 

追加:

[self dismissModalViewControllerAnimated:YES]; 

、それだけで正常に動作する必要があります。

あなたは結果を見てする必要はありません

+0

ありがとう、私はそれを追加することを完全に忘れました、ありがとう! – Jon

0

次のコードを使用

(表示したい場合にのみ、ユーザーが実際にヒットしなかった場合、送信例えば、警告か何かを「ありがとう」)
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 

    switch (result) 
    { 

     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved: you saved the email message in the Drafts folder"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email"); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error"); 
      break; 
     default: 
      NSLog(@"Mail not sent"); 
      break; 
    } 

    [self dismissModalViewControllerAnimated:YES]; 
} 
関連する問題