从模拟器发送邮件时出现问题

时间:2011-04-29 10:36:37

标签: iphone objective-c xcode

我正在尝试创建一个小型电子邮件应用。一切正常但电子邮件不发送。我是否为此做了些什么。我正在自学。所以我缺少一些东西。这是我的代码..

-(void)viewDidLoad
{
    UIButton *but01 = [UIButton buttonWithType:UIButtonTypeRoundedRect];                    //Button I
    but01.frame = CGRectMake(240,10, 70, 50);
    [but01 setTitle:@"ADD" forState:UIControlStateNormal];
    [but01 addTarget:self action:@selector(sendMail) 
    forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:but01];


}

- (IBAction)sendMail {
    if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *mfViewController = [[MFMailComposeViewController alloc] init];
        mfViewController.mailComposeDelegate = self;

        [self presentModalViewController:mfViewController animated:YES];
        [mfViewController release];
    }else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Your phone is not currently configured to send mail." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];

        [alert show];
        [alert release];
    }
}


#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate Methods

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];

    switch (result) {
        case MFMailComposeResultCancelled:
            alert.message = @"Message Canceled";
            break;
        case MFMailComposeResultSaved:
            alert.message = @"Message Saved";
            break;
        case MFMailComposeResultSent:
            alert.message = @"Message Sent";
            break;
        case MFMailComposeResultFailed:
            alert.message = @"Message Failed";
            break;
        default:
            alert.message = @"Message Not Sent";
        break;  }
    [self dismissModalViewControllerAnimated:YES];

    [alert show];
    [alert release];
}

为此,我在控制台中收到此消息。我现在能做什么?

29/04/11 4:03:04 PM SpringBoard[3115]   Reloading application state for 'com.yourcompany.Sendmail' as its modification date has changed    
29/04/11 4:03:04 PM com.apple.launchd.peruser.501[95]   (UIKitApplication:com.yourcompany.Sendmail[0x38e1][3206]) Exited: Killed    
29/04/11 4:03:04 PM SpringBoard[3115]   Reloading and rendering all application icons.    
29/04/11 4:03:04 PM SpringBoard[3115]   Application 'Sendmail' exited abnormally with signal 9: Killed

1 个答案:

答案 0 :(得分:2)

MFMailCompose在模拟器中不起作用,请在设备上检查