CSV not attaching to in app email?

后端 未结 3 1926
鱼传尺愫
鱼传尺愫 2021-01-27 10:40

So I have had this problem for sometime and just cant get it working! I have been building a survey app that users simply enter information in and its saved to a csv file. Im no

3条回答
  •  不知归路
    2021-01-27 10:59

    So after many sleepless nights and a lot of trying different ways I finally found the way that works with a friend (see code below)

     NSString *docsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        NSData *attachment = [NSData dataWithContentsOfFile:[docsDirectory stringByAppendingPathComponent:@"results.csv"]];
    
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
        [mailer setToRecipients:@[@"gpsflighttrial@gcap.eu"]];
        [mailer setSubject:self.subject.text];
        [mailer setMessageBody:self.message.text isHTML:NO];
        [mailer addAttachmentData:attachment mimeType:@"application/csv" fileName:@"results.csv"];
        [self presentModalViewController:mailer animated:YES];
    

    Just in case anyone has this problem in the future.

提交回复
热议问题