简体   繁体   中英

How do I send an e-mail with attachment from iPad

I am developing an experiment in Unity engine (3.4) , it is supposed to run on iPad (iOS5). I do most of my scripting in Monodevelop (2.4.2). After the experiment is over, the results are saved in a text file and stored within the program. I can access them via synchronizing with iTunes, but i want to implement an extra feature - i want to be able to send the file via e-mail. For the starters, the e-mail address can be hardwired into the program.

What i need to implement is as follows:

If the participant in finished:

  1. close the file
  2. compose the message using the hardwired address and the file
  3. check if the ipad has access to the internet
  4. if yes - send the message and place it in the 'sent' of my mail app.
  5. if no - place the message into the outbox of my mail app.

I have experience with GUI and IO scripting, but i have hardly dealt with networking in any programming language, i have no idea where to start. Unity API and Unity Answers were not very helpful.

If you have any useful links or bits of code I could learn from, i would greatly appreciate it.

you can use the MFMailComposeViewController and attach you data as NSData like this

if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init];
    controller.mailComposeDelegate=self;
    [controller setToRecipients@"..."];
    [controller setSubject:@"Your Subject"];

    NSData* attachmentData = ...
    [controller addAttachmentData:attachmentData mimeType:@"..." fileName:@"..."];
    [self presentModalViewController:controller animated:YES];
    [controller release];
}

and dont forget to implement the delegate to dismiss the modal mail view controller

- (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    [self dismissModalViewControllerAnimated:YES];
}

the user needs to have the mail app to be configured and press manually the send button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM