Objective C: Send email without leaving app

前端 未结 3 1766
悲哀的现实
悲哀的现实 2020-11-30 22:19

How do I send an email within an app without leaving the app.

This works:

-(void) sendEmailTo:(NSString *)to withSubject:(NSString *)subject withBo         


        
3条回答
  •  春和景丽
    2020-11-30 23:13

    Yes. Use the MFMailComposeViewController.

    // From within your active view controller
    if([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
        mailCont.mailComposeDelegate = self;
    
        [mailCont setSubject:@"yo!"];
        [mailCont setToRecipients:[NSArray arrayWithObject:@"joel@stackoverflow.com"]];
        [mailCont setMessageBody:@"Don't ever want to give you up" isHTML:NO];
        [self presentViewController:mailCont animated:YES completion:nil];
    
    }
    
    
    // Then implement the delegate method
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    

提交回复
热议问题