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

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top