无法将附件发送到其他电子邮件地址

时间:2013-01-04 04:56:34

标签: iphone objective-c ios xcode

在我的应用中,使用MFMailComposer我无法将附件发送到其他邮件地址。 这些附件在链接中。

我正在使用此代码:

 NSData *textData = [NSData dataWithContentsOfFile:self.fileString];
[mailView addAttachmentData:textData mimeType:@"text/plain" fileName:self.fileString];

2 个答案:

答案 0 :(得分:2)

尝试使用以下代码在电子邮件中发送附件..

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Subject"];
NSData *textData = [NSData dataWithContentsOfFile:self.fileString];
[picker addAttachmentData:imageData mimeType:@"text/plain" fileName:@"rainy"];
[self presentViewController:picker animated:YES completion:nil];
[picker release];

你在addAttachmentData方法中做的是将fileName中的self.fileString替换为我写过的其他名称。 让我知道它的工作与否。

答案 1 :(得分:0)

我猜文件名是文本文件的路径。然后将此路径(self.fileString)传递给-addAttachmentData:mimeType:fileName:。使用附加数据到邮件是不正确的。你只需要设置一个普通字符串作为附件文件的文件名,也许@“attachText.txt”将是一个不错的选择。