WEB开发网
开发学院手机开发iPhone 开发 在 iPhone App 里发送带附件 Email 的实现代码 阅读

在 iPhone App 里发送带附件 Email 的实现代码

 2010-05-29 05:40:00 来源:WEB开发网   
核心提示:想在iPhone App里添加能发送附件的Email功能,可以加入messageUI.framework添加附件代码NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString

想在iPhone App里添加能发送附件的Email功能。可以加入messageUI.framework

添加附件代码

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *pathHome = [path objectAtIndex:0];

NSString *filePath = [pathHome stringByAppendingPathComponent:@"info.txt"];

if( [MFMailComposeViewController canSendMail] )

{

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

[picker setSubject:@" "];

NSLog(@"filePath = %@",filePath);

NSData* data = [NSData dataWithContentsOfFile:filePath];

[picker addAttachmentData:data mimeType:@"txt" fileName:@"info.txt"];

NSString *emailBody = @" ";

[picker setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:picker animated:YES];

[picker release];

}

用回调函数mailComposeController查看发送状态。

Tags:iPhone App 发送

编辑录入:coldstar [复制链接] [打 印]
赞助商链接