Format RTF file to be sent as body using Mfmailcomposeviewcontroller

Asked

Viewed 92 times

3

I have to send a report in text (with formatting) that I put in an RTF file within my project.

When I set the email body using the method below, the formatting of the RTF file is not recognized by Mfmailcomposeviewcontroller.

Follows code I am using and the Nsstring returned from my RTF file:

NSString *path = [[NSBundle mainBundle] pathForResource:@"relatorio"
                                                 ofType:@"rtf"];

NSString *emailBody = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

[picker setMessageBody:emailBody isHTML:NO];

I tried several encodings and did not change the content of emailBody, below follows the beginning of Nsstring emailBody:

{\rtf1\ansi\ansicpg1252\cocoartf1265
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\qc

\f0\b\fs24 \cf0 Relat\'f3rio \
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
\cf0 Desenvolvido por Finaltap\

Putting into HTML is not an option as the report is too large and was taken from an MS Word file.

Any idea???

1 answer

1

The simplest idea is to send it as an attachment. If you have no need to make changes at runtime, it is an extremely simple solution and should solve your problem.

You will start a NSDatawith the contents of the file and pass it on addAttachmentData of picker. Done!

Now if you really need to put the content directly in the body of the email, I believe it will take some conversions to HTML. You say that changing the source file is not an option, but I will quote the possibility to make this conversion in Runtime.

The NSAttributedString has a initWithData that supports receiving a NSData file RTF. After conversion, you will probably be able to get text in attributed strings or even in HTML, if it works correctly with the generated output.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.