Objective C: Bold Message Body in MFMailComposeViewController - ios

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];

Related

stringByAppendingPathComponent adds a '/' character to the text

I have the following code:
NSString *message;
if (some_condition) {
message = #"String 1. ";
} else {
message = #"String 2. ";
}
message = [message stringByAppendingPathComponent:#"Bla bla bla."];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Alert"
message:message
preferredStyle:UIAlertControllerStyleAlert];
The text that I see when the alert pops up has an extra '/' character where the string were appended:
Where did it come from and how do I remove it?
You are using the wrong method there.
Instead of :
message = [message stringByAppendingPathComponent:#"Bla bla bla."];
Use:
message = [message stringByAppendingString:#"Bla bla bla."];
When you use stringByAppendingPathComponent: it will return a new string made by appending the provided string to the receiver, preceded if necessary by a path separator.
Reference : NSString Class Reference

Localized String including emoji codes not working

My question is while
NSLocalizedStringFromTableInBundle(#"Sample Text", #"Localizable", [Globals GetLocalizebundle], #"")
is working perfect and I get Localised string from file but
NSLocalizedStringFromTableInBundle(#"Sample Text \U0001F431", #"Localizable", [Globals GetLocalizebundle], #"")
can't get Localised text from bundle.
Any help appreciated.
I solved this by replacing whole unicode code with "surrogates".
For example 😁 has code "1F601" it's surrogates are D83D and DE01. So 😁 should be localised as "\UD83D\UDE01"
Don't use translated text for key, use something like
"sample_text_emoji" = "Sample Text \U0001F431";
in your localized.string file and then use
NSLocalizedStringFromTableInBundle(#"sample_text_emoji", #"Localizable", [Globals GetLocalizebundle], #"")
Documentation clearly states this is a key, so use it as a key, not a text
NSString *NSLocalizedStringFromTableInBundle(NSString *key, NSString *tableName, NSBundle *bundle, NSString *comment)
Actually, below solved my question but I still don't believe it is a proper solution. Anyway here the code resolves emoji characters for NSLocalizedStringFromTableInBundle:
NSString *str = NSLocalizedStringFromTableInBundle(#"Sample Text", #"Localizable", [Globals GetLocalizebundle], #"");
NSString *stringWithEmoji = [str stringByAppendingString:#" \U0001F431"];
NSData *data = [stringWithEmoji dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *valueUnicode = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *dataa = [valueUnicode dataUsingEncoding:NSUTF8StringEncoding];
NSString *valueEmoji = [[NSString alloc] initWithData:dataa encoding:NSNonLossyASCIIStringEncoding];
Where base Localized.string includes "Sample Text" = "Sample Text";
The method is to get Localised text from bundle and then add emoji Unicode to string. Then convert it to NSNonLossyASCIIString. This method is working if you are using same emojis for every language.

HTML in MFMailComposeViewController

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];
}

enabling email only if within specific location

I have created an app which i only want to work if the user is within a specific area (i.e. i only want the user to be able to sent an email if they are within a specific state of the country)
can some please either-
a) point me in the direction of a tutorial on how to set up a GPS boundary, and how to check if a user is within said GPS boundary
or
b) write an example for creating a GPS area, and how to check if the user is within the area.
i have the latitude and longitude of the user stored to variables.
here is my location manager code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"didUpdateToLocation: %#", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
longditute = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
Latitude = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
}
// Stop Location Manager
[locationManager stopUpdatingLocation];
}
and my email code:
-(IBAction)actionEmailComposer{
if ([MFMailComposeViewController canSendMail]) {
if ([witnessResponse isEqual: #"Yes"]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc]init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[NSString stringWithFormat:#"Dob in a Hoon Report(Y)"]];
[mailViewController setMessageBody:[NSString stringWithFormat:#"Am I prepared to be called upon as a witness?: %# \n Rego Number: %# \n Vehicle Make: %# \n Vehicle Colour: %# \n Vehicle Type: %# \n Incident Date: %# \n Incident Time: %# \n Incident Location: %# \n Do I know the Driver?: %# \n Drivers Name (if Known) %# \n Driver Gender: %# \n Description of Incident: %# \n Name of Person Reporting Incident: %# \n Contact Number: %# \n" , witnessResponse, regoNumber.text, vehilceMake.text, vehilceColour.text, vehicleType.text, incidentDate.text, incidentTime.text, location.text, driverKnownResponse, driverName.text, driverGenderResponse, additionalInfo.text, usersName.text, usersPhoneNumber.text] isHTML:NO];
[self presentViewController:mailViewController animated:YES completion:nil];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[mailViewController addAttachmentData:imageData mimeType:#"image/jpg" fileName: [NSString stringWithFormat:#"Dob in a Hoon %# , %#.jpg", Latitude,longditute]];
[mailViewController setToRecipients:toRecipients];
} else {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc]init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[NSString stringWithFormat:#"Dob in a Hoon Report(N)"]];
[mailViewController setMessageBody:[NSString stringWithFormat:#"Am I prepared to be called upon as a witness?: %# \n Rego Number: %# \n Vehicle Make: %# \n Vehicle Colour: %# \n Vehicle Type: %# \n Incident Date: %# \n Incident Time: %# \n Incident Location: %# \n Do I know the Driver?: %# \n Drivers Name (if Known) %# \n Driver Gender: %# \n Description of Incident: %# \n Name of Person Reporting Incident: %# \n Contact Number: %# \n" , witnessResponse, regoNumber.text, vehilceMake.text, vehilceColour.text, vehicleType.text, incidentDate.text, incidentTime.text, location.text, driverKnownResponse, driverName.text, driverGenderResponse, additionalInfo.text, usersName.text, usersPhoneNumber.text] isHTML:NO];
[self presentViewController:mailViewController animated:YES completion:nil];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[mailViewController addAttachmentData:imageData mimeType:#"image/jpg" fileName: [NSString stringWithFormat:#"Dob in a Hoon %# , %#", Latitude,longditute]];
[mailViewController setToRecipients:toRecipients];
}
}
else{
NSLog(#"Device is unable to send email");
}
}
my goal is: if the person is outside the area, i want to display a UIAlert informing the user they are outside the area. If the person is inside the area, it will go through the email set up.
You want the CLLocationManager, and methods like startMonitoringForRegion:, which uses CLCircularRegion objects to define geographic regions.
If you look in the Xcode docs for startMonitoringForRegion, it has a link to a demo project called "Regions", which should get you started.

NSNotification alert body issue

i want to print in notification body like today is jane's birthday
for that i am using logic like below
notification.alertBody = [NSString stringWithFormat:#"Today is %#'s Birthday", [_combinedNameArray objectAtIndex:i]];
but in notification it only shows the name which is jane and not showing Today is birthday
plz tell me what i am doing wrong ?
thank you
Try:
notification.alertBody = [NSString stringWithFormat:#"Today is %#\'s Birthday", [_combinedNameArray objectAtIndex:i]];
(' character needs an escape character)

Resources