1

I am working on a quiz app where the user's input will be stored inside a plist files. I tried researching for various ways to attach files to an email, but mostly are all for JPEG and TXT files.

I have created a plist and tried to attach the it the same way, but on the mailcomposer it only shows the filename of the attachment.

    -(NSString *) dataFilePath
{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [path objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:@"Answer.plist"];
}

This is the code in the composer

-(IBAction) openEmail {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
    [mailComposer setToRecipients:[NSArray arrayWithObjects:@"secondary_Example@email.com", nil]];
    [mailComposer setSubject:@"Subject Topic"];
    [mailComposer setMessageBody:@"Message Body" isHTML:NO];
    [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];


    NSString *path = [[NSBundle mainBundle] pathForResource:@"Answer" ofType:@"plist"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [mailComposer addAttachmentData:myData mimeType:@"application/xml" fileName:@"Answers"];

       [self presentModalViewController:mailComposer animated:YES]; }}

Am I missing something out? Please help.. Would really appreciate it.

4

0 回答 0