Question

My code shows a "Parse Issue - Expected Statement" error and I don't know what needs to be changed or added to fix it.

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"matt_srfgtr@hotmail.com", nil]];
        [composer setSubject:@"subject here"];
        [composer setMessageBody:@"message here"isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:composer animated:YES completion:nil];
    }
    else
        }

The expected statement error shows for this curly bracket ^

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"error"
                              message:[NSString stringWithFormat:@"error %@", [error description]]
                              delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
Was it helpful?

Solution

Try this code :

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"matt_srfgtr@hotmail.com", nil]];
        [composer setSubject:@"subject here"];
        [composer setMessageBody:@"message here"isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:composer animated:YES completion:nil];
    }
    else {

    }
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"error"
                              message:[NSString stringWithFormat:@"error %@", [error description]]
                              delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

OTHER TIPS

The problem lies in your -(IBAction)email method. It has an else statement without braces. Just remove it and re-run.

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"matt_srfgtr@hotmail.com", nil]];
        [composer setSubject:@"subject here"];
        [composer setMessageBody:@"message here"isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentViewController:composer animated:YES completion:nil];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top