将AddressbookUI address.text保存到Documents目录,以便在InApp电子邮件中使用

时间:2010-01-10 20:29:00

标签: iphone email addressbook

我正在尝试使用回收代码来保存图像并将其附加到电子邮件中,但没有运气。从PeoplepickerNavigation控制器中获取三个值后,我想保存它们以供使用,并将它们作为文本放入电子邮件中。我现在得到的是我的电子邮件正文中名为“addresssend”的放置图像,如何从“addresssend”文件中提取文本,以便用户看到firstName,lastname和&地址。

以下是保存代码:

- (IBAction)saveData {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedDataPath = [documentsDirectory stringByAppendingPathComponent:@"addresssend.txt"];
NSString *addresssend = lastName.text; // lastName is from the LastNameProperty
[addresssend writeToFile:savedDataPath atomically:NO];  
}

以下是检索代码:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile2 = [documentsDirectory stringByAppendingPathComponent:@"addresssend.txt"];
NSData *myData2 = [[[NSData alloc] initWithContentsOfFile:appFile2] autorelease];
[picker addAttachmentData:myData2 mimeType:@"text/txt" fileName:@"addresssend"];

我可以看到这将如何存放文件,任何人都可以指向正确的方向,以便电子邮件正文显示实际名称&地址?

谢谢,

迈克尔

1 个答案:

答案 0 :(得分:0)

搜索MFMailComposeViewController并查看一些教程。您已经询问了一系列相关问题,可以通过Google搜索该组件来解答。

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO]; 
[self presentModalViewController:controller animated:YES];
[controller release];