开发者

attachment of file in compose mail in iphone

I am making a window 开发者_JAVA百科based application. In this I have put some entries which become record for one person now I have put mailcomposer to send mail but I want to send the record in mail of that person in attachment automatically. Can I set document or excel file in mailcomposer in iphone application.

If anyone know please help me.

Thanks alot.


The MFMailComposeViewController protocol defines the method you need. Using the method

- (void)addAttachmentData:(NSData *)attachment mimeType:(NSString *)mimeType fileName:(NSString *)filename __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

you can easily add any kind of file as an attachment to the mail. The easiest way would be to combine the records you stored in an CSV string and store data inside ass attachment. See below for an example:

MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
[picker setSubject:@"New Contacts"];
NSMutableString *body = [[NSMutableString alloc] init];
[body appendString:@"Hi, see attachment\n\n"];


NSMutableString *csv = [[NSMutableString alloc] init];
// Add data to csv
// ...

[picker addAttachmentData:[csv dataUsingEncoding:NSStringEncodingConversionExternalRepresentation allowLossyConversion:NO]
                 mimeType:@"text/csv"
                 fileName: @"contacts.csv"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜