我想將標籤文本附加到電子郵件中, 如何將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];
}
}
如何鏈接該標籤附加該電子郵件?
任何幫助將不勝感激。
你想寄的是什麼格式?一個.txt文件? – Martol1ni
@woz他要求發送self.label.text不是磁盤上的某個文件 –
@woz我的問題是,使用此代碼時,我可以看到郵件視圖控制器打開時的attachment.txt,但收到的電子郵件中沒有任何內容時,我不知道爲什麼。你能幫我麼 ? – 4slices