HTML in MFMailComposeViewController - ios

I am a new in Xcode and i was working with mail app which uses MFMailComposeViewController. I wanted to design my *messageBody with HTML. Actually its a small "BOOK A MEETING" app. So I wanted to put date and time feild so that user could choose date and time. But when i run my app, i cannot enter anything in my date and time feild. Here is my code. Hope i could get some help.
- (IBAction)BookAMeeting:(id)sender {
//email subject
NSString *emailTitle = #"Haven Support";
//email content
NSMutableString *messageBody = [NSMutableString string];
[messageBody appendString:#"<h1>Please Enter the following feilds to book a meeting.</h1>\n"];
[messageBody appendString:#"<form>NAME: <input type = 'text' name='fname'> \n <br>TIME: <input type = 'time' name='timee'><br>\n DATE: <input type = 'date' name='date'><br>"];
//to address
NSArray *toRecipents = [NSArray arrayWithObject:#"xyz#hotmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc]init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:YES];
[mc setToRecipients:toRecipents];
//present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}

Related

When using a "share" feature what is typed in the caption to include the users new score?

I have created a "Share" button in my app so you can send an automated caption to others through message, Facebook, twitter, etc... What do I type in the caption that allows the user to send his/her current score? I know there's something simple that people type like "%d" that grabs the score and places it inside the message.
Thank you.
else if ([touchedNode.name isEqualToString:#"share"]) {
[self runAction:[SKAction playSoundFileNamed:#"coin.mp3" waitForCompletion:NO]];
NSString *caption = #"Yo check out my new score "%d" ! ";
UIImage *imageToShare = [UIImage imageNamed:#"banner.png"];
NSURL *urlToShare = [NSURL URLWithString:#"itms://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=949315818&mt=8"];
NSArray *activityItems = #[caption, urlToShare, imageToShare];
UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
UIViewController *root = self.view.window.rootViewController;
[root presentViewController:vc animated:YES completion:nil];
}
Replace this:
NSString *caption = #"Yo check out my new score "%d" ! ";
With this:
NSString *caption = [NSString stringWithFormat:#"Yo check out my new score \"%d\"!", currentScore];
NSString's stringWithFormat: allows you to interpolate values into strings in complex ways.
The \'s are necessary to escape the double quotes inside a string delimited with double quotes.

NSMutableArray UTF8 (Cyrillic, Chinese etc) store in NSString to email

I have a
NSMutableArray *myArray;
and
#property (strong, nonatomic) NSMutableArray *myArray;
declared in the .h file.
In .m, myArray stores some (Cyrillic) Russian characters and shows up in the UITableView fine in Russian. HOwever, I want to email this, so I added
- (void)viewDidLoad
superArray=[[NSMutableArray alloc]init];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [superArray count];
}
and also this
NSString *emailString =[myArray description];
With the typical code:
NSString *messageBody = emailString;
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setMessageBody:messageBody isHTML:YES];
However, it's showing up with things like: \U0425\U044d etc etc
I figured since HTML is enabled I could add something like:
(EDITED HTML )
NSString *htmlportionBegin =#"<!DOCTYPE html> <html><head><meta charset='UTF-8'> </head><body>";
NSString *htmlportionEnd =#"</body></html>";
NSString *messageBody_Pre = [htmlportionBegin stringByAppendingString:emailString];
NSString *messageBody = [messageBody_Pre stringByAppendingString:htmlportionEnd];
But that doesn't change anything.
Anyone know how to get this to work so that the email composer in the app can read in the Russian characters?
Never use the description method to generate output to be seen by the user.
Instead, build your own string from the contents of the array. One possible way would be:
NSString *emailString = [myArray componentsJoinedByString:#", "]; // or use #"\n"
This will give you better output.
And if you state that the message body is HTML then you should have proper HTML tags in the message body including the html and body tags.

Add saved email string to email recipient

To save user time when emailing, user saves there email address in a preferences page that should pre fill the recipient when email is composed. (or thats what im trying to do) Here is where im stuck, how do I use my saved string to an object for the purpose of pre filling the recipient.
Currently the string does not pre fill the recipient
saves here in preferences page:
NSString *savecontents = _emailAddress.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savecontents forKey:#"saveEmail"];
[defaults synchronize];
Reads here in mail view presentation
- (IBAction)email:(id)sender {
NSString *savedValue = [[NSUserDefaults standardUserDefaults] <---------- saved email string
stringForKey:#"saveEmail"];
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:savedValue]; <------- trying to get string here
[mail setToRecipients:toRecipients];
[mail setSubject:#"subject"];
NSString *emailBody = [NSString stringWithFormat: #"text here"] ;
[mail setMessageBody:emailBody isHTML:YES];
mail.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mail animated:YES];
}
tried so far:
NSArray *toRecipients = [NSString stringWithFormat:savedValue];
[mail setToRecipients:toRecipients];
and
NSArray *toRecipients = [NSString stringWithFormat:#"%#",savedValue];
[mail setToRecipients:toRecipients];
and
Google, SO and banging fist on desk
All you need is this:
if (savedValue.length) {
[mail setToRecipients:#[ savedValue ]];
}
This uses modern Objective-C array syntax. This would be the same as:
if (savedValue.length) {
NSArray *toRecipients = [NSArray arrayWithObject:saveValue];
[mail setToRecipients:toRecipients];
}
The code you have you are trying to assign an NSString value to an NSArray variable.
Also, please don't use stringWithFormat unless you actually have a need to format a string.

Objective C: Bold Message Body in MFMailComposeViewController

I have this code
NSString *messageBody = [NSString stringWithFormat:#"Name: %#\nCompany/Institution: %#\nAddress: %#\nCity: %#\nCountry: %#\nContact Number: %#\nE-Mail: %#\n \n \n Message: %#", rName.text, rCompany.text, rAddress.text, rCity.text, rCountry.text, rContactNumber.text, rEmail.text, rDescription.text];
[tempMailCompose setMessageBody:messageBody isHTML:NO];
to fill contents on the MFMailComposeViewController Now what I want to do is to make the Name, Address, City, Country, Contact Number, E-Mail, and Message to be bold. What I did was to insert <strong> but the result was wrong it also displays <strong>as text.
How will I able to bold it?
Try this
NSString *messageBody = [NSString stringWithFormat:#"Name: <b>%#</b><br/>Company/Institution: <b>%#</b><br/>Address: <b>%#</b><br/>City: <b>%#</b><br/>Country: <b>%#</b><br/>Contact Number: <b>%#</b><br/>E-Mail: <b>%#</b><br/> <br/> <br/> Message: <b>%#</b>", rName.text, rCompany.text, rAddress.text, rCity.text, rCountry.text, rContactNumber.text, rEmail.text, rDescription.text];
[tempMailCompose setMessageBody:messageBody isHTML:YES];

Launching MFMailComposeViewController cuts off recipient text

I am using Apple's sample code for the MessageUI and MFMailComposeViewControllerDelegate, and mostly it works great. But for some reason when I implement it, the text in the recipient fields appears out of alignment with the field labels, and you can only see half of the cursor and half of the text while typing. Once you've typed the addresses and exited the field, the text is completely visible, though still out of alignment with the labels. I have looked at other apps' implementations of the MessageUI, and they do not seem to have this problem. has anyone seen this problem and found a solution?
Below is code:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Data"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"email#example.com"];
[picker setToRecipients:toRecipients];
// Attach an attachment to the email
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *csvFile = [documentsDirectory stringByAppendingPathComponent:#"myFile.csv"];
NSData *myData = [NSData dataWithContentsOfFile:csvFile];
NSString *filename = #"myFile.csv";
[picker addAttachmentData:myData mimeType:#"text/csv" fileName:filename];
// Fill out the email body text
NSString *emailBody = #"Attached is the data";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
The problem occurs in both the simulator and on device.
Probably, you've got a custom UITextField in your app and have some custom code in - (CGRect)textRectForBounds:(CGRect)bounds. If you'd like to have some category for UITextField class, try to put your specific code directly to the class where you using that instead of using category, which affects all textfields in your app, even in MFMailComposeViewController

Resources