Question

I am sending HTML formatted email from within the iPhone app. I am reading HTML file stored within the application package.

Now, I want to change certain text within the HTML file, I.e. there is name,email and phone which will change depending on certain selections by the user in the app.

How to add these varying parameters to HTML file content?

Please help.

Thanks

Was it helpful?

Solution

Something like this may work for you:

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"yourHtml" ofType:@"html"];

NSError *error = nil;

NSString *inputHtml = [[NSString alloc] initWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:&error];

NSString *nameParsedHtml = [inputHtml stringByReplacingOccurrencesOfString:@"Name:" withString:[NSString stringWithFormat:@"Name: %@", self.nameField.text]];

NSString *emailParsedHtml = [nameParsedHtml stringByReplacingOccurrencesOfString:@"Email:" withString:[NSString stringWithFormat:@"Email: %@", self.emailField.text]];

NSString *outputHtml = [emailParsedHtml stringByReplacingOccurrencesOfString:@"Phone:" withString:[NSString stringWithFormat:@"Phone: %@", self.phoneField.text]];

NSLog(@"Output html string is: %@", outputHtml);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top