Сбой приложения по электронной почте на устройстве - PullRequest
0 голосов
/ 05 сентября 2011

Я добавил функцию «Электронная почта» в своем приложении для iPhone, и она зависает на iPhone, но работает на симуляторе. Пожалуйста, объясните, почему происходит сбой на устройстве

это код

-(IBAction)sendMail{
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"Contact"];

    [controller setToRecipients:[NSArray arrayWithObject:@"Contact@BettorsSidekick.com"]];
    [controller setMessageBody:@"" isHTML:NO];
    [self presentModalViewController:controller animated:YES];
    [controller release];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller  
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError*)error;
{
    if (result == MFMailComposeResultSent) {
        NSLog(@"It's away!");
    }
    [self dismissModalViewControllerAnimated:YES];
}

Ответы [ 3 ]

2 голосов
/ 05 сентября 2011

используйте этот код, он отлично работает.

-(IBAction)Btn_EmailPressed:(id)sender{
    if (![MFMailComposeViewController canSendMail]) {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Email cannot be configure." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }else {
        picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate=self;
        [picker setToRecipients:nil];
        [picker setSubject:@"Email"];
        [picker setMessageBody:nil isHTML:NO];
        NSArray *toRecipients = [[NSArray alloc] initWithObjects:lblSite.text,nil];
        [picker setToRecipients:toRecipients];
        [self presentModalViewController:picker animated:YES];
    }
}


- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    NSString *msg1;
    switch (result)
    {
        case MFMailComposeResultCancelled:
            msg1 =@"Sending Mail is cancelled";
            break;
        case MFMailComposeResultSaved:
            msg1=@"Sending Mail is Saved";
            break;
        case MFMailComposeResultSent:
            msg1 =@"Your Mail has been sent successfully";
            break;
        case MFMailComposeResultFailed:
            msg1 =@"Message sending failed";
            break;
        default:
            msg1 =@"Your Mail is not Sent";
            break;
    }
    UIAlertView *mailResuletAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)];
    mailResuletAlert.message=msg1;
    mailResuletAlert.title=@"Message";
    [mailResuletAlert addButtonWithTitle:@"OK"];
    [mailResuletAlert show];
    [mailResuletAlert release];
    [self dismissModalViewControllerAnimated:YES];  
}
2 голосов
/ 05 сентября 2011

, если вы не настроили какую-либо учетную запись электронной почты на своем устройстве iphone, это может быть причиной сбоя, потому что когда вы вызываете mfmailcomposer, он будет работать на симуляторе, но не будет работать на устройстве, и в результате произойдет сбой, поэтому настройте почту наустройство, попробуйте код выше.

1 голос
/ 05 сентября 2011

попробуйте

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];


    if(controller && [MFMailComposeViewController canSendMail]){

        controller.mailComposeDelegate = self;
        [controller setSubject:@"Contact"];

        [controller setToRecipients:[NSArray arrayWithObject:@"Contact@BettorsSidekick.com"]];
        [controller setMessageBody:@"" isHTML:NO];
        [self presentModalViewController:controller animated:YES];


    }

if (controller) {

    [controller release];        

}
...