我想将标签文本附加到电子邮件中,如何将 UILabel 中的文本作为电子邮件的附件发送?
这是我正在使用的代码:
-(IBAction)send:(id)sender {
if ([MFMailComposeViewController canSendMail])
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 100)];
label.numberOfLines = 0;
label.textAlignment = UITextAlignmentCenter;
label.text = @"text";
[self.view addSubview:label];
[label release];
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Subject"];
NSString *fileName = @"my file.txt";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
NSData *myData = [NSData dataWithContentsOfFile:path];
[mailer addAttachmentData:myData mimeType:@"text/plain" fileName:fileName];
// Fill out the email body text
NSString *emailBody = @"Email Body";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
else
{
UIAlertView *alertm = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Please make sure that your email application is open"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertm show];
[alertm release];
}
}
如何链接该标签以将其附加到电子邮件?
任何帮助将不胜感激。