MailComposeViewController - 当我按下“取消”按钮时,我看不到带有“草稿”,“保存草稿”和“取消”按钮的面板

时间:2010-10-06 12:30:17

标签: iphone xcode ios4

我正在使用MFMailComposeViewController控制器:

MFMailComposeViewController *picker1 = [[MFMailComposeViewController alloc] init];
 picker1.mailComposeDelegate = self;
 [picker1 setSubject:@"I have a pencil for you"];
 UIImage *roboPic = [UIImage imageNamed:@"RobotWithPencil.jpg"];
 NSData *imageData = UIImageJPEGRepresentation(roboPic, 1);
 [picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"RobotWithPencil.jpg"];
 NSString *emailBody = @"This is a cool image of a robot I found.  Check it out!";
 [picker1 setMessageBody:emailBody isHTML:YES];
 picker1.navigationBar.barStyle = UIBarStyleBlack; 
 [self presentModalViewController:picker1 animated:YES];
 [picker1 release];

当我按下“取消”按钮时,我没有看到带有“草稿”,“保存草稿”和“取消”按钮的面板,屏幕被锁定/冻结但是没有出现上面提到的按钮的面板

我很乐意得到任何帮助。

提前致谢 摩西

1 个答案:

答案 0 :(得分:1)

you have to use this for mail composing. and in interface file write this  delegte MFMailComposeViewControllerDelegate . also import messageUi framework. its working.


#pragma mark Compose Mail
// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayComposer
{
    if(![MFMailComposeViewController canSendMail])
    {
        [self setUpMailAccount];
        return;
    }

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Strpy's Revange"];
   [[picker navigationBar] setTintColor:[UIColor blackColor]];


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

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

    // Fill out the email body text

    if([UIAppDelegate gameCodeFlag]==0)
    {
        NSString *emailBody = [NSString stringWithFormat:@"Game Score! %d",[UIAppDelegate scorePost]];
        [picker setMessageBody:emailBody isHTML:NO];
    }
    else {
        [UIAppDelegate readFriendPlist];
        NSString *emailBody = [NSString stringWithFormat:@"Game Code! %@",[UIAppDelegate gameCode]];
        [picker setMessageBody:emailBody isHTML:NO];
    }

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



// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            break;
        case MFMailComposeResultSent:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Sending..."
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            [alert release];
            break;
        }
        case MFMailComposeResultFailed:
            break;          
        default:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Sending Failed - Unknown Error :-("
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            [alert release];
        }
        break;
    }
    [self dismissModalViewControllerAnimated:YES];
    if([UIAppDelegate gameCodeFlag]==1)
    {
        [[CCDirector sharedDirector] pushScene:[StorePage scene]];

    }


}